小白教程
所有教程
关于
Search
108.162.216.107
108.162.216.107
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Css position”的源代码
本页内容
上一节:
Html_outerwidth
下一节:
Html_prepend
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:position()}}[[Category:jquery ref html|22]] = jQuery position() 方法 = [[jquery ref html|jQuery HTML/CSS 方法]] 返回 <p> 元素的 top 和 left 位置: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ x=$("p").position(); alert("Top: " + x.top + " Left: " + x.left); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ x=$("p").position(); alert("顶部位置: " + x.top + "左部位置: " + x.left); }); }); </script> </head> <body> <p>这是一个段落。</p> <button>返回P元素的顶部和左部的位置</button> </body> </html> </run> == 定义和用法 == position() 方法返回第一个匹配元素的位置(相对于它的父元素)。 该方法返回一个带有两个属性(以像素为单位的 top 和 left 位置)的对象。 == 语法 == <pre> $(selector).position()</pre> == 更多实例 == [[try.php?filename=tryjquery_css_position2|返回元素相对于它的父元素的位置]] 如何获取 <p> 元素在 <div> 元素内部的位置。 [[jquery ref html|jQuery HTML/CSS 方法]]
返回至“
Css position
”。
上一节:
Html_outerwidth
下一节:
Html_prepend