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

获取元素到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>

  

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