js各种高度的获取总结图示兼容pc手机端

it2022-05-05  164

js各种高度的获取

距离父元素顶部的距离

// js ele.offsetTop; // jq $('ele').offset().top;

网页被卷起来的高度

// js document.documentElement.scrollTop || document.body.scrollTop window.pageYOffset // jq $(window).scrollTop()

元素的高度/宽度

// js document.querySelector('.eleClass').clientHeight; // jq $('.eleClass').height();

窗口的高度

//js window.innerHeight || document.documentElement.clientHeight

getBoundingClientRect

//元素顶部距窗口顶部的距离 element.getBoundingClientRect().top //元素底部部距窗口顶部的距离 element.getBoundingClientRect().bottom

原文链接  https://bigma.cc/2019/07/18/jsHeight/


最新回复(0)