正确的动态效果
<script>
function getPos(ev)
{
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
return {x: ev.clientX+scrollLeft, y: ev.clientY+scrollTop};
}
document.onmousemove=function (ev)
{
var aDiv=document.getElementsByTagName('div');
var oEvent=ev||event;
var pos=getPos(oEvent);
aDiv[0].style.left=pos.x+'px';
aDiv[0].style.top=pos.y+'px';
for(var i=aDiv.length-1;i>0;i--)
{
aDiv[i].style.left=aDiv[i-1].offsetLeft+'px';
aDiv[i].style.top=aDiv[i-1].offsetTop+'px';
}
};
</script>
错误的动态效果`
<script>
document.onmousemove=function (ev){
var oDiv=document.getElementsByTagName('div');
var oEvent=ev||event;
oDiv[0].style.left=oEvent.clientX+'px';
oDiv[0].style.top=oEvent.clientY+'px';
for(var i=0;i<oDiv.length-2;i++){
oDiv[i+1].style.left=oDiv[i].offsetLeft+'px';
oDiv[i+1].style.top=oDiv[i].offsetTop+'px';
}
}
</script>