English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Il metodo offset() di jQuery ottiene o imposta le coordinate di offset relativamente al documento dell'elemento selezionato.
quando si utilizza il metodo offset()ottenereimpostare l'offset, esso restituiràil primo elemento selezionatole coordinate di offset (un oggetto con 2 attributi: top e sinistra)).
quando si utilizza il metodo offset()impostareimpostare l'offset, esso imposteràtutti gli elementi selezionatile coordinate di offset.
ottenere le coordinate di offset:
$("selettore").offset()
impostare le coordinate di offset:
$("selettore").offset({cima: valore, sinistra: valore})
$("p").offset($("div").offset());
$("selettore").offset(function(index, currentOffset))
ottenere le coordinate di offset del paragrafo:
示例 let p = $("p"); let offset = p.offset(); p.html("sinistra: " + offset.left + " ", "cima: " + offset.top); return newCord;});
impostare le coordinate di offset di tutti i paragrafi:
示例 $("p").offset({ cima: 60, sinistra: 30 return newCord; return newCord;});
使用另一个元素的偏移量坐标设置元素的偏移量坐标:
示例 使用另一个元素的偏移量坐标设置元素的偏移量坐标: return newCord;});
$("p").offset($("div").offset());
示例 $("button").click(function(){ $("p").offset(function(i, val){ let newCord = new Object(); newCord.left = val.left + 100; newCord.top = val.top + 100; return newCord; return newCord;});
参数值 | 参数 |
---|---|
描述, left:{top:, left:value | } |
指定像素的顶部和左侧坐标 | function(index, currentOffset)
|