2

I used this code, but it's well only for Y-coordinate

$('div').mousemove(function(e){
    var x = Math.floor(e.pageX - $(this).offset().left);
    var y = Math.floor(e.pageY - $(this).offset().top);

    $('.status').html(x+' '+y);

});

X-coordinate show me wrong values.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Fifa Lan
  • 61
  • 3

1 Answers1

1

Does anything change if you replace

var x = Math.floor(e.pageX - $(this).offset().left);
var y = Math.floor(e.pageY - $(this).offset().top);

with

var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • yes, this is the same, but my code was a lit bit wrong, lol [jfiddle](http://jsfiddle.net/Stasonix/mkZP2/) – Fifa Lan Dec 31 '11 at 15:17