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(); }