获得网页中元素的位置

网页大小: clientWidth和clientHeight。

最快速的方法:getBoundingClientRect() 获得top, right, bottom, left,是获得元素距离viewport的左上角。

获得元素的相对位置:不断向父元素获得offsetHeight和offsetWidth。

获得元素的绝对位置:最后减去 document.docuemnetElement.scrollTop 和 scrollWidth。

 

posted @ 2018-03-07 14:49  bounce  阅读(181)  评论(0编辑  收藏  举报