I would like to show something at the mouse down place, I tried to use :
$('#my-graph').mousedown(function(evt){
// show object at:
var x= evt.screenX, y=evt.screenY;
//or show object at:
var x2=evt.pageX, y2=evt.pageY;
//code to render object at (x,y) and (x2,y2)
......
});
But neither of the above (x, y) and (x2,y2) place the rendered object at the mouse clicked place, and show the object some distance away from mouse down place, why?
I render the object with a position attributes, the position is relative to the #my-graph div, left up most corner of the div is supposed to be the origin point(0,0)
I would like to show something at the mouse down place, I tried to use :
$('#my-graph').mousedown(function(evt){
// show object at:
var x= evt.screenX, y=evt.screenY;
//or show object at:
var x2=evt.pageX, y2=evt.pageY;
//code to render object at (x,y) and (x2,y2)
......
});
But neither of the above (x, y) and (x2,y2) place the rendered object at the mouse clicked place, and show the object some distance away from mouse down place, why?
I render the object with a position attributes, the position is relative to the #my-graph div, left up most corner of the div is supposed to be the origin point(0,0)
Share Improve this question edited Sep 13, 2019 at 8:03 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Sep 30, 2011 at 10:04 Leem.finLeem.fin 42.7k86 gold badges219 silver badges370 bronze badges 3- What do you expect the coordinates to mean? I mean, relative to what? The page, the screen or an element? – pimvdb Commented Sep 30, 2011 at 10:07
- Do you render the object using proper position attributes? E.g. position: absolute in relevance to screen? – Przemek Commented Sep 30, 2011 at 10:07
- Yes, I render the position with a position attributes, in relavant with the #my-graph div, left up most corner of the div is supposed to be the origin point – Leem.fin Commented Sep 30, 2011 at 10:09
1 Answer
Reset to default 5You seem to want offsetX
and offsetY
: http://jsfiddle/f52Gg/.
$("div").mousedown(function(e){
alert(e.offsetX + " " + e.offsetY);
});