码迷,mamicode.com
首页 > Web开发 > 详细

获取元素到body/html的距离函数

时间:2016-09-10 11:46:05      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

获取元素到body的距离:

<script>
	function offsetDis(obj) {
		var l = 0, t = 0;
		while(obj) {
			l = l + obj.offsetLeft + obj.clientLeft;
			t = t + obj.offsetTop + obj.clientTop;
			obj = obj.offsetParent;
		}
		return {left: l, top: t};
	}
</script>

  

 

获取元素到body/html的距离函数

标签:

原文地址:http://www.cnblogs.com/handsomehan/p/5858974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!