我需要能够计算出 HTML 元素 (div) 应该有多高...
我正在使用此 javaScript 代码来计算 CSS 并将其添加到我的“Wrapper”div:
var h=window.innerHeight;
var content=920;
var fix=920-h;
document.getElementById("wrapper").style.height= +fix+ 'px';
但它根本不起作用......
有什么帮助吗?
最佳答案
您可能在加载正文之前运行此脚本。
要在主体加载完成后加载它,请将您的代码替换为:
window.onload = function(){
var h=window.innerHeight;
var content=920;
var fix=920-h;
document.getElementById("wrapper").style.height= +fix+ 'px';
}
关于javascript - 使用 javaScript 变量添加 css 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16001913/