解释处的两个问题:<!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>
添加回答
举报
0/150
提交
取消