为了账号安全,请及时绑定邮箱和手机立即绑定

jquery的offset.top用原生js怎样写

jquery的offset.top用原生js怎样写

杨__羊羊 2019-02-19 17:12:00
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>

 



 


查看完整回答
反对 回复 2019-02-26
  • 1 回答
  • 0 关注
  • 631 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信