jQuery的position()方法
来源:互联网 发布:html在线视频聊天源码 编辑:程序博客网 时间:2024/05/16 06:53
position()方法的定义和用法:
此方法获取匹配元素相对某些元素的偏移量。
返回的对象包含两个整型属性(top和left)的对象。
此方法只对可见元素有效。
语法结构:
$(selector).position()
在教程的开头之所以说是获取匹配元素相对于某些元素的偏移量。很多教程都说方法返回的偏移量是相对于父元素,其实并非完全如此,此方法会将匹配元素以绝对定位方式处理,当然并不是说真的将匹配元素设置为绝对定位。方法的偏移量参考原则如下:
1.如果父辈元素中没有采用定位的(position属性值为relative、absolute或者fixed),那么偏移量参考对象为窗口。
2.如果父辈元素中有采用定位的,那么偏移量的参考对象为距离它最近的采用定位的元素,
实例代码:
<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>position()函数-蚂蚁部落</title><style type="text/css">*{ margin:0px; padding:0px;}.father{ background-color:green; width:200px; height:200px; padding:50px; margin-bottom:50px; margin-left:100px;}.children{ height:150px; width:150px; background-color:red; line-height:150px; text-align:center;}</style><script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script><script type="text/javascript">$(document).ready(function(){ $(".children").each(function(){ var text; text="left:"+$(this).position().left; text+="top:"+$(this).position().top; $(this).text(text); })})</script></head><body><div class="father" style="position:relative"> <div class="children"></div></div><div class="father"> <div class="children"></div></div></body></html>
0 0
- jQuery的position()方法
- jquery中position方法参数的含义
- jQuery之position()方法的具体使用
- jQuery中position()方法和offset()方法的区别
- jQuery CSS 操作 - position() 方法
- jQuery CSS 操作 - position() 方法
- jquery对象的position和offset方法理解
- jQuery操作css-position()与offset()方法的区别
- Jquery中的offset()和position()方法详解
- jQuery中offset和position方法
- jQuery方法position()与offset()区别
- jquery position
- jquery position
- jquery position
- jquery position
- IE8中Jquery slideUp、slideDown方法由Position属性引起的Bug
- jQuery源码分析之offset,position,offsetParent方法以及源码中常见的cssHooks,swap代码
- Position:absolute居中的方法
- HDU 5296 Annoying problem
- [c语言]宏中##的用法(续)
- 动态链接库DLL(2)
- [LeetCode]Minimum Depth of Binary Tree
- 毕向东 笔记
- jQuery的position()方法
- 不管流程,你凭什么当人家的老板?
- 枚举 poj2965 The Pilots Brothers' refrigerator
- OpenGL学习笔记(1)--开发环境搭建
- hihoCoder - 1174 - 拓扑排序·一
- ofbiz设置主页log
- copypngfile error 的问题
- 手机网络制式全解析
- vs2010程序打包教程