【发布时间】:2015-01-28 09:08:11
【问题描述】:
我正在尝试将导航栏附加到正确的滚动位置。
我有一个#cover-section 元素,在它下面是一个可附加的导航栏。
#cover-section 元素可调整大小。当它被调整大小时,我也希望修改附加偏移位置,但 coverHeight 变量似乎没有更新。 coverHeight 的值最初为 0,并且始终保持为零。
如何在.resize() 函数范围内获取coverHeight 变量以实际修改在事件范围之外声明的变量值?
$(document).ready(function() {
var coverHeight;
coverHeight = 0;
$(window).resize(function() {
$('#cover-section').height($(window).height() - $('#navbar').height());
return coverHeight = $('#cover-section').height();
});
$('.affixable-wrapper').height($('.affixable-wrapper > .affixable').height());
return $('.affixable-wrapper > .affixable').affix({
offset: coverHeight
});
});
【问题讨论】:
标签: javascript jquery scope affix