为了账号安全,请及时绑定邮箱和手机立即绑定

javascript执行顺序

javascript执行顺序

牛肉速冻矮子 2017-05-19 13:48:49
解释处的两个问题:<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <style type="text/css">                 #outer{                           margin: 0 auto;                           text-align: center;     //  问题一: why???  不写画布不居中                 }        </style>    </head>    <body>    <div id="outer">             <canvas id="myCanvas" width="320px" height="480px" ></canvas>    </div> <script type="text/javascript">var myCanvas = document.getElementById("myCanvas");var ctx = myCanvas.getContext("2d"); //背景图function drawBackground(){          ctx.fillStyle = "rgb(35,45,50)";          ctx.fillRect(0,0,myCanvas.width,myCanvas.height);}//分数图function drawScore(){ ctx.fillStyle = "#CCFF99"; ctx.font = "16px sans-serif"; ctx.fillText("Score:" + score,10,24);}       //问题二:分数画布为什么不出现 //文档加载监听事件document.addEventListener("DOMContentLoaded",drawBackground());</script>       </body></html>
查看完整描述

2 回答

已采纳
?
日光弥散

TA贡献4条经验 获得超4个赞

问题1,你要给#outer设置一个宽度  不然margin:0 auto没用

问题2,不调用当然不会出来

查看完整回答
反对 回复 2017-05-19
?
Stardust1001

TA贡献261条经验 获得超78个赞

你调用了吗??????
查看完整回答
反对 回复 2017-05-19
  • 2 回答
  • 0 关注
  • 1555 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信