【发布时间】:2014-05-15 09:36:40
【问题描述】:
我正在使用 jQuery 来动态定位我的页脚,现在的问题是
$(window).height();
错了,因为我包含了一个导航使用:
$('.navigation').load('includes/navigation.html');
之后我检查但 $(window).height() 不包括添加项目的高度,我在检查高度之前添加项目,这样就不会出现问题。我也试过 $(document).ready() 和 $(window).load()
这是完整的代码
$(window).load(function(){
$('.navigation').load('includes/navigation.html');
var docheight = $(document).height();
var winheight = $(window).height();
console.log('window: ' + winheight + ', document: ' + docheight);
});
【问题讨论】:
-
你应该在
load()完成回调中设置你的逻辑,load()是异步的 -
添加 DOM 元素不会影响
$(window).height(),这是正确的行为。 -
@RoryMcCrossan 是的,对不起,即使那样 OP 也应该使用
$(document).height();,对吧?! -
是的。虽然他说他是。在这种情况下问题是否仍然存在 OP?
-
你是对的!使用 .load 回调有效!如果你把它作为一个答案,我会接受它! :) 谢谢!
标签: javascript jquery height jquery-load