jQuery offset() 方法
jQuery 教程
· 2019-03-27 15:12:29
实例
返回 <p> 元素的偏移坐标:
$("button").click(function(){
var x=$("p").offset();
alert("Top: " + x.top + " Left: " + x.left);
});
定义和用法
offset() 方法设置或返回被选元素相对于文档的偏移坐标。
当用于返回偏移时:
该方法返回第一个匹配元素的偏移坐标。它返回一个带有两个属性(以像素为单位的 top 和 left 位置)的对象。
当用于设置偏移时:
该方法设置所有匹配元素的偏移坐标。
语法
返回偏移坐标:
$(selector).offset()
设置偏移坐标:
$(selector).offset({top:value,left:value})
使用函数设置偏移坐标:
$(selector).offset(function(index,currentoffset))
| 参数 | 描述 |
|---|---|
| {top:value,left:value} | 当设置偏移时是必需的。规定以像素为单位的 top 和 left 坐标。 可能的值:
|
| function(index,currentoffset) | 可选。规定返回包含 top 和 left 坐标的对象的函数。
|
点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html
The Starfish and the Spider
Ori Brafman、Rod A. Beckstrom / Portfolio Hardcover / 2006-10-05 / USD 24.95
Understanding the amazing force that links some of today's most successful companies If you cut off a spider's leg, it's crippled; if you cut off its head, it dies. But if you cut off a st......一起来看看 《The Starfish and the Spider》 这本书的介绍吧!