Move Image Everywhere Mouse Goes

[Total: 0    Average: 0/5]

This example traps the mouse movement to readjust where the mouse is.

Head Code:

<script type=text/javascript src="/bin/div_construct_ns6.js"></script>
<script type=text/javascript>
var isNS4=document.layers?true:false;
var isIE=document.all?true:false;
var isNS6=!isIE&&document.getElementById?true:false;
var _m1 = '<img height=30 width=30 border=0 src="/js/images/pic1.gif">';
var d1 = new NewDiv(window,"ball",_m1,0,0,0,0,0,"ABSOLUTE");
var offsetX = 15; // 1/2 width of image 
var offsetY = 15; // 1/2 height of image
function movePic() {
  d1.moveTo(mouseX-offsetX,mouseY-offsetY);
}
var timer = setInterval('movePic()',40);
var mouseX = 0;
var mouseY = 0;
function getMousePosition(e) {
  mouseX = (isNS4||isNS6) ? e.pageX : document.body.scrollLeft+event.clientX;
  mouseY = (isNS4||isNS6) ? e.pageY : document.body.scrollTop+event.clientY;
}
if (isNS6)  document.addEventListener("mousemove", getMousePosition, true);
if (isNS4) document.captureEvents(Event.MOUSEMOVE);
if(isIE||isNS4)document.onmousemove=getMousePosition;
</script>

Body Code:

<script>
d1.output();
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *