Alternative to offsetLeft and offsetTop?
I wrote a little canvas application and finally tried to incorporate it into my blog, however now I find that on a mouse click offsetLeft and offsetRight are always 0.
I don't really know why, but how do I get that info back?
In case anyone is not seeing the tags on this post: yes I am using jQuery for mouse events.
$('#'+canvasId).mousedown(function(e){
that.mouse.down = true;
that.mouse.downx = e.pageX-this.offsetLeft;
that.mouse.downy = e.pageY-this.offsetTop;
that.mouse.dialogDown = k.operations.interface.getHudItem(that.mouse.downx, that.mouse.downy);
k.operations.interface.mouseDown(that.mouse.downx, that.mouse.downy);
}开发者_C百科);
Is this work?
var offset = jQuery(this).css('offset');
alert( 'Left: ' + offset.left + '\nTop: ' + offset.top );
It should be offset.left
and offset.top
, not offsetLeft
and offsetTop
.
try this
$('#'+canvasId).mousedown(function(e){
tt = $( this );
tof = tt.offset()
that.mouse.down = true;
that.mouse.downx = e.pageX-tof.left;
that.mouse.downy = e.pageY-tof.top;
that.mouse.dialogDown = k.operations.interface.getHudItem(that.mouse.downx, that.mouse.downy);
k.operations.interface.mouseDown(that.mouse.downx, that.mouse.downy);
});
精彩评论