Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript计算文档高度_Javascript_Jquery_Css - Fatal编程技术网

使用JavaScript计算文档高度

使用JavaScript计算文档高度,javascript,jquery,css,Javascript,Jquery,Css,我已经开发了一个使用JQuery的网站,并使用JQuery命令在页面上应用了所有样式,这样我就可以使用从javascript函数(如window.innerHeight)中提取的数字来计算属性值。它工作得很好。但是现在我试图计算文档的高度(注意,不是窗口高度),减去页脚的高度,然后在页脚上方放置一个“阴影”图像。不过,我在这方面遇到了麻烦,因为Safari似乎误算了这个数字,随意地定位了阴影元素,似乎每次都会出现一个稍微不同的位置 $("div#shadowBottom").css({ "pos

我已经开发了一个使用JQuery的网站,并使用JQuery命令在页面上应用了所有样式,这样我就可以使用从javascript函数(如window.innerHeight)中提取的数字来计算属性值。它工作得很好。但是现在我试图计算文档的高度(注意,不是窗口高度),减去页脚的高度,然后在页脚上方放置一个“阴影”图像。不过,我在这方面遇到了麻烦,因为Safari似乎误算了这个数字,随意地定位了阴影元素,似乎每次都会出现一个稍微不同的位置

$("div#shadowBottom").css({
"position":"absolute",
"top":(window.scrollMaxY-$(".footer").css("height").replace("px","")-50)+"px",
"left":"0px",
"width":"100%"
"height":"50px"
});
我还尝试过将文档包装在div中,并计算其高度减去.footer元素的高度和#shadowBottom元素的高度,但没有效果

您可以尝试以下方法:

var body = document.body;
var html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, 
                   html.clientHeight, html.scrollHeight, html.offsetHeight );

下面的代码工作得很好:

$("div#gradientBottom").css({
    "background":"url(\"gradientBottom.png\")",
    "position":"absolute",
    "top":(Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight)-$(".footer").css("height").replace("px","")-50)+"px",
    "left":"0px",
    "width":"100%",
    "height":"50px"
});