html5 canvas fillRect坐标和大小的问题解决方法
2014-03-26 17:03
477 查看
fillRect(100,100,100,100) 前2个100是指坐标,后2个100是指宽和高。
今天学习html5 的canvas,发现fillRect的坐标和大小一直不对,研究了半天,发现canvas的宽度和高度必须内联在canvas标签中才对。郁闷了半天。
错误的方式1:
错误的方式2:
显示结果:
正确的方式:
今天学习html5 的canvas,发现fillRect的坐标和大小一直不对,研究了半天,发现canvas的宽度和高度必须内联在canvas标签中才对。郁闷了半天。
错误的方式1:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #mycanvas{ width: 200px; height: 200px; background: yellow; } </style> </head> <body> <canvas id='mycanvas' ></canvas> <script> var c = document.getElementById('mycanvas'); var ctx = c.getContext("2d"); ctx.fillStyle='#f36'; ctx.fillRect(100, 100, 100, 100); </script> </body> </html>
错误的方式2:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id='mycanvas' style='width:200px;height:200px;background:yellow'></canvas> <script> var c = document.getElementById('mycanvas'); var ctx = c.getContext("2d"); ctx.fillStyle='#f36'; ctx.fillRect(100, 100, 100, 100); </script> </body> </html>
显示结果:
正确的方式:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id='mycanvas' width='200px' height='200px' style='background:yellow'></canvas> <script> var c = document.getElementById('mycanvas'); var ctx = c.getContext("2d"); ctx.fillStyle='#f36'; ctx.fillRect(100, 100, 100, 100); </script> </body> </html>
相关文章推荐
- html5 canvas坐标和大小的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- 关于realarm S5P4418的u-boot显示内存大小问题解决方法
- IOS中html5上传图片方向问题解决方法
- 解决html5 + js开发APP无法显示SVG问题(转化成canvas)
- PHP和Nginx 文件上传大小限制问题解决方法
- android下载问题。本地与网络资源大小不一致解决方法
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- 使用drbd进行磁盘扩容,小磁盘扩容大磁盘后大小未变的问题解决方法
- Android 编程时,res/raw文件夹内容大小的限制问题及解决方法
- 解决html5 + js开发APP无法显示SVG问题(转化成canvas)
- WPF下、使用Double作为点坐标带来的问题或line直线颜色不明显的问题的解决方法
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- html5 canvas 画图移动端出现锯齿毛边的解决方法
- “超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。”问题的解决方法