Jump to content

mouse tracking


knowram

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.