jquery的offset.top用原生js怎樣寫
1 回答

郎朗坤
TA貢獻1921條經驗 獲得超9個贊
你好,原生的寫法是這樣的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style> *,body{padding:0; margin:0} .div{position:absolute; left:0px; top:50px; width:50px; height:50px; background-color:#006} </style> </head> <body> <div class="div" id="obj"></div> <script type="text/javascript"> var obj = document.getElementById("obj"); alert(obj.offsetTop) </script> </body> </html>
|
- 1 回答
- 0 關注
- 718 瀏覽
添加回答
舉報
0/150
提交
取消