我是靠谱客的博主 俏皮电脑,这篇文章主要介绍Uncaught TypeError: Cannot read property 'offsetTop' of null,现在分享给大家,希望可以做个参考。
在获取内容区块高度(无滚动)时使用offsetTop报如下错误:
Uncaught TypeError: Cannot read property ‘offsetTop’ of null
实现效果如图:
主要js代码
// 内容可视区域的高度
clientHeight = document.documentElement.clientHeight;
// 减去头部和底部的高度及上下外边距
colHeight = clientHeight - 60 - document.getElementById("cover-page").offsetTop;
// 界面的内容区高度
document.getElementById("cover-page").style.height = colHeight + "px";
修改后代码
// 内容可视区域的高度
clientHeight = document.documentElement.clientHeight;
// 减去头部和底部的高度及上下外边距,设置高度
cover_page = document.getElementById("cover-page");
cover_page.style.height = (clientHeight - cover_page.offsetTop - 60) + "px";
最后
以上就是俏皮电脑最近收集整理的关于Uncaught TypeError: Cannot read property 'offsetTop' of null的全部内容,更多相关Uncaught内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复