jquery position() method


  Translation results:

position

UK[pəˈzɪʃn] US[pəˈzɪʃən]

n. Position, direction; status, position; attitude; status

vt .Place; put... in a proper position; position...; garrison troops

jquery position() methodsyntax

Function: The position() method returns the position (offset) of the matching element relative to the parent element. The object returned by this method contains two integer properties: top and left, measured in pixels. This method only works on visible elements.

Syntax: $(selector).position()

jquery position() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    x=$("p").position();
    alert("Left position: " + x.left + " Top position: " + x.top);
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>获得 p 元素的位置坐标</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A