Jump to content

Recommended Posts

I have seen adds on different pages where there is a cat on the bottom of the image and when you move your mouse over the image a ball moves with it and the cat moves his head back and forth following the ball. Or ones where a target follows the mouse and  you have to shout something.

My question is what language provides this real time mouse tracking, and what is it called?

I am trying to build this into a site.

Thanks for any info
Link to comment
https://forums.phpfreaks.com/topic/35128-mouse-tracking/
Share on other sites

Here's a little something I've been playing with.

[code]
<html>
<script>
document.onmousemove= function (e){followMouse(e); }


function followMouse(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}

mark(posx,posy)
}


function mark(x,y)
{
var d = document.getElementById('coords')
d.value=x+' x '+y;
d.style.left=parseInt(x+20)+'px';
d.style.top =parseInt(y+20)+'px';
}
</script>

<input type="text" id="coords" style="position:absolute;top:0px;left:0px;">
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35128-mouse-tracking/#findComment-165930
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.