考虑到浏览器的兼容性,可使用三种语法获取页面高度
-
1、window.pageYOffset页面Y轴的偏移量
-
2、document.documentElement.scrollTop 文档的html元素的高度
-
3、document.body.scrollTop 在IE下,获取html的高度
//该语句判断是否需要进行fixed定位
let scrollTop =
window.pageYOffset||document.documentElement。scrollTop|| document.body.scrollTop;
initHeight(){
this.isFixed = scrollTop > 152?true:false;
}