*{marg...">
美文网首页
canvas画十字准标

canvas画十字准标

作者: f675b1a02698 | 来源:发表于2017-09-14 16:12 被阅读0次

header("Content-type:text/html;charset=utf-8");

?>

*{margin:0;padding:0;border:0;}

#myCanvas{

}

Your browser does not support the HTML5 canvas tag.

//画鼠标为交叉点的十字

function dh(x,y){

var c=document.getElementById("myCanvas");

var ctx=c.getContext("2d");

ctx.canvas.width  = window.innerWidth;

ctx.canvas.height = window.innerHeight;

ctx.lineWidth = 1;

ctx.strokeStyle = 'rgba(0,0,255,1)';

ctx.clearRect(0,0,2000,1000);

ctx.beginPath();

ctx.moveTo(x-0.5,0);

ctx.lineTo(x-0.5,y-40.5);

ctx.moveTo(x-0.5,y+40.5);

ctx.lineTo(x-0.5,1000);

ctx.moveTo(0,y-0.5);

ctx.lineTo(x-40.5,y-0.5);

ctx.moveTo(x+40.5,y-0.5);

ctx.lineTo(2000.5,y-0.5);

ctx.rect(x-40.5,y-40.5,81,81);

ctx.stroke();

}

/* document.onmousemove=function(e){

e=e||window.event;

var x=e.clientX,y=e.clientY;

setTimeout(function(){

dh(x,y);

},20)

} */

function e(){

dh(Math.round(Math.random()*window.innerWidth),Math.round(Math.random()*window.innerHeight));

}

window.setInterval(e,Math.round(Math.random()*2000)+2000);

相关文章

网友评论

      本文标题:canvas画十字准标

      本文链接:https://www.haomeiwen.com/subject/jffnjxtx.html