开发者

Tracking mouse movements

开发者 https://www.devze.com 2023-03-04 12:06 出处:网络
This should be typically easy, I want to perform tracking of mouse movements. I\'m capable of capturing the XY co-ords.

This should be typically easy, I want to perform tracking of mouse movements. I'm capable of capturing the XY co-ords.

However, as far as I'm aware, this will vary according to the browser size, right ?

If so, can anyone recommend other things to track to ensure my results are accurate?

P.s I'm using 开发者_如何学Cthe following Jquery example

$("html").mousemove(function(e){
var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
$("span:first").text("( e.pageX, e.pageY ) - " + pageCoords);
$("span:last").text("( e.clientX, e.clientY ) - " + clientCoords);
});


Coordinates are independent of the browser size.

Hope this helps. Cheers

PS: Use $(window).mousemove or $(document).mousemove instead of $("html").mousemove, it's a better practice.

0

精彩评论

暂无评论...
验证码 换一张
取 消