獲得 <p> 元素當前的偏移:
$(".btn1").click(function(){
x=$("p").offset()
;
$("#span1").text(x.left);
$("#span2").text(x.top);
});
offset() 方法返回或設(shè)置匹配元素相對于文檔的偏移(位置)。
設(shè)置所有匹配元素的偏移坐標。
$(selector).offset(value)
參數(shù) | 描述 |
---|---|
value |
必需。規(guī)定以像素計的 top 和 left 坐標。 可能的值:
|
使用函數(shù)來設(shè)置所有匹配元素的偏移坐標。
$(selector).offset(function(index,oldoffset))
參數(shù) | 描述 |
---|---|
function(index,oldoffset) |
規(guī)定返回被選元素新偏移坐標的函數(shù)。
|
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答?。?點擊進入論壇