用html5的canvas标签绘制圆.矩形比较容易,绘制三角形,坐标确定相当于前面两种难点,这里绘制的是正三角形,比较容易,我们只需要把鼠标刚按下去的点设置为三角形的中心点,鼠标抬起的点设置为三角形右边的点,再通过数学计算就可以计算出左边和顶点的坐标. //绘制三角形 function drawPoly(num){ //设置全局变量,便于在匿名函数中使用 var startX; var startY; var endX; var endY; var distance; //获取鼠标按下事件(起始…
转自:http://www.cnblogs.com/artwl/archive/2012/02/28/2372042.html 作者:Artwl 背景 今天在博问中看到一个问题:用canvas 的 lineto方法画对角线,但画出来的图形不对? 这是一个很常见的误区,这里给大家细说一下. 原理 在w3网站上是这样解释的: The canvas element has two attributes to control the size of the coordinate space: width…
<!DOCTYPE HTML> <html> <body> <canvas id="myCanvas">your browser does not support the canvas tag </canvas> <script type="text/javascript"> var canvas=document.getElementById('myCanvas'); var ctx=canv…
javascript方法: var oC=document.querySelectorAll('canvas')[0];oC.width=document.documentElement.clientWidth;oC.height=document.documentElement.clientHeight;//oC.width=window.innerWidth;//oC.height=window.innerHeight; css方法: html,body{width:100%;height:…
h5标签canvas关于getImageData跨域的问题 在学习h5的时候,canvas标签中getImageData()报错:security error! 具体代码如下(chrome浏览器): function createGSCanvas(img){ var canvas=document.createElement("canvas"); canvas.width=img.width; canvas.height=img.height; var ctx=canvas.getCo…