I'm trying to make a navbar affixable at the proper scroll position.
I have a #cover-section
element and below it, an affixable navbar.
The #cover-section
element is resizable. when it gets resized, I want the affixing offset position to be modified as well, but the coverHeight
variable doesn't seem to be updating. The coverHeight
value initially is 0, and always remains zero.
How do I get the coverHeight variable within the .resize()
function scope to actually modify the variable value that was declared outside of the event's scope?
$(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
});
});