offset 使用

<html>
    <head>
<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript"> function testoffset(){ var $n1 = $("#n1"); // 输出n1的当前坐标 var coord = $n1.offset(); alert( "当前坐标:(" + coord.left + ", " + coord.top + ")" ); // 当前坐标 var offset = $n1.offset( {top: 200, left: 200}); var coord2 = $n1.offset(); alert( "当前坐标:(" + coord2.left + ", " + coord2.top + ")" ); // 修改后坐标 } </script>
    </head>

    <body>
<p id="n1">111</p>
 <p onclick="testoffset()">click</p>

    </body>
</html>

你可能感兴趣的:(offset)