0

我有一个图标<img src="res/img/b_drop.png" id="drop_1" />。单击此图标时,我需要在某些坐标处出现提示,我将通过我的 S 和 Y 点计算这些坐标#drop_。我可以做些什么来使用 jQuery 计算这两个点?

4

2 回答 2

3

偏移量可能是你想要的

$('#drop_1').on('click', function(){
    var offset = $(this).offset();
    alert('top - ' + offset.top + "\n left - " + offset.left);
});

这将从文档的顶部和左侧提醒元素的位置

jQuery 偏移量()

这里有一个

演示

于 2013-07-25T12:49:46.600 回答
0

相对父元素:

$('#drop_1').position().left // x coord
$('#drop_1').position().top // y coord

相对页面:

$('#drop_1').offset().left // x coord
$('#drop_1').offset().top // y coord
于 2013-07-25T12:47:00.793 回答