Uncaught TypeError: Cannot read property 'offsetTop' of null
2016-10-29 14:53
1046 查看
在获取内容区块高度(无滚动)时使用offsetTop报如下错误:
Uncaught TypeError: Cannot read property ‘offsetTop’ of null
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 'hasOwnProperty' of null
- Uncaught TypeError: Cannot read property of 'name' null
- 关于"Uncaught TypeError: Cannot read property 'time' of null"的处理
- Uncaught TypeError: Cannot read property 'click' of null问题的解决
- Uncaught TypeError: Cannot read property 'value' of null
- Uncaught TypeError: Cannot read property 'length' of null
- js提示Uncaught TypeError: Cannot read property 'options' of null
- 关于js Uncaught TypeError: Cannot read property 'style' of null 问题
- JavaScript:Uncaught TypeError Cannot read property 'id' of null。
- discuz 出现了Uncaught TypeError: Cannot read property 'appendChild' of null
- js事件处理程序 Uncaught TypeError: Cannot read property 'addEventListener' of null
- Uncaught TypeError: Cannot read property 'querySelector' of null
- 在开发Ext 项目中如果遇到 Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null
- 把script放在head里出现Uncaught TypeError: Cannot set property 'scrollTop' of null(…)
- Uncaught TypeError: Cannot read property 'value' of null
- Uncaught TypeError: Cannot read property 'prototype' of null using Openerp 7.0
- canvas出现Uncaught TypeError: Cannot read property 'getContext' of null 错误
- 在使用renderTo中遇到的Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null
- Uncaught TypeError: Cannot read property 'width' of null
- Uncaught TypeError: Cannot read property 'getItem' of null