Link to home
Start Free TrialLog in
Avatar of PSERK
PSERK

asked on

Image following cursor

Hi Programmers!
I am not JavaScript programmer but I have to make a little script:
I need an small image that constantly follows a cursor.
Something like you move a cursor and with a small delay an image will follow it or something like that.

If possible then please help!!!

Okey, all the best!
Avatar of snoyes_jw
snoyes_jw
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of radnor
radnor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zvonko
Here my version:


<html>
<head>
<script>
var imgCur = null;
function moveImg(e){
  if(!e){
    e=event;
  } else {
    e.x = e.pageX;
    e.y = e.pageY;
  }
  setTimeout("imgCur.style.left='"+e.x+"px';imgCur.style.top='"+e.y+"px'", 100);
  status="imgCur.style.left='"+e.x+"px';imgCur.style.top='"+e.y+"px'";
}
function intitCur(){
  imgCur=document.images.curImg;
  if(!document.all)
    document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove=moveImg;
}
</script>
</head>
<body onLoad="intitCur()">
<img name="curImg" style="position:absolute;" src="https://www.experts-exchange.com/images/vipAccess.gif">
</body>
</html>


Sorry, remove the window.status line. It was only for debugging.