Javascript offsetLeft和offsetTop的替代方案?

Javascript offsetLeft和offsetTop的替代方案?,javascript,jquery,Javascript,Jquery,我编写了一个小的canvas应用程序,并最终尝试将其合并到我的博客中,但是现在我发现鼠标点击offsetLeft和OffsetLight总是0 我真的不知道为什么,但是我怎么才能得到这些信息呢 如果有人看不到这篇文章上的标签:是的,我正在使用jQuery来处理鼠标事件 $('#'+canvasId).mousedown(function(e){ that.mouse.down = true; that.mouse.downx = e.pageX-this.offsetLeft;

我编写了一个小的canvas应用程序,并最终尝试将其合并到我的博客中,但是现在我发现鼠标点击offsetLeft和OffsetLight总是0

我真的不知道为什么,但是我怎么才能得到这些信息呢

如果有人看不到这篇文章上的标签:是的,我正在使用jQuery来处理鼠标事件

$('#'+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);
});
这是工作吗

var offset = jQuery(this).css('offset');
alert( 'Left: ' + offset.left + '\nTop: ' + offset.top );
它应该是offset.left和offset.top,而不是offsetLeft和offsetTop。

试试这个

 $('#'+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);
});