HTML5一个简单的鼠标跟随事件。

<canvas id="cc" width="798" height="1131"></canvas>

 

$(document).mousemove(function(e){
	if(e.pageX || e.pageY){
		mouseX=e.pageX;
		mouseY=e.pageY;
		lili();
	}else{
		mouseX=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
		mouseY=e.clientY+document.body.scrollLeft+document.documentElement.scrollLeft;  

                lili();
	}
});
var colors = ['#e37f7f','#e37fd6'];//全局变量

 

function lili(){
	var mc=document.getElementById('cc');
	var context=mc.getContext('2d');
	context.beginPath();
	context.fillStyle=colors[1];
	context.arc(mouseX,mouseY,10,0,Math.PI*2,false);
	context.closePath();
	context.fill();	
}

 

posted @ 2012-09-03 17:57  平阳小安  阅读(613)  评论(0编辑  收藏  举报