为什么背景增加在每次点击使用$(文档).height()?



我使用$(document).height()来动态分配背景的高度。

为什么当文档被点击时背景图像会增加它的高度?文档高度相同

function setDocumentHeight(){
var height = $(document).height(); console.log("Document Height " + height);
$(".bg").css({"height":height});

}
setDocumentHeight();

$(document).click(function(e) {
if (e.button == 0) { setDocumentHeight(); }
});

https://jsfiddle.net/jd8n6qa9/

set top and bottom 0 to absolute background。这将解决这个问题。

.bg {top:0;bottom:0;}