I have <header> and <nav> blocks that are affected by JavaScript. What I would like is for the <nav> block to become position: static if the user resizes the window to smaller than 1119px wide. The script currently works only on page load, but does not detect resize.
I've tried applying the solution from this question, but with no luck. Here's a link to the webpage in question:
Here's my JavaScript so far:
<script>
$(document).ready(function(){
var $window = $(window);
function checkWidth() {
windowsize = $window.width();
if (windowsize > 1119) {
$(window).scroll(function() {
if ($(this).scrollTop()>119)
{
$('header').fadeOut();
$('nav').css({position: 'fixed', top: '0px'});
}
else
{
$('header').fadeIn();
$('nav').css({position: 'absolute', top: 'auto'});
}
});
}
else {
$('nav').css({position: 'static', top: '0px'});
}
}
// can trigger the resize handler instead of
// explicitly calling checkWidth()
$(window).resize(checkWidth).resize();
});
</script>
windowsize = $window.width();try addingvarbeforewindowsize.