I'm making a website for my territory group. Well the template is good on the whole, but there's something I don't quite know how to achieve. In the body there are two divs. The upper one has a height of 100vh. The downer one is for news and articles. I put a nav over the second which of course is in a static position set. Now what I want to achieve is to make it fixed once you reach its container div by scrolling down. I've searched a lot for this, and it seems fair to say that pretty much looks like the jQuery "scroll to fixed" case. I am pretty new to jQuery, although I can understand it a bit because I am more familiar with PHP, but for some reason the script didn't work. It may also be because of some missing plugin script in the head, so please if you have the answer don't forget to include the plugin scripts to add in the head. Anyway, here's the example script of what I tried (combining with css class to which I gave position: fixed;
and top: 0;
values)
$(function(){
$(window).scroll(function() {
if ($(this).scrollTop() >= 290) {
$('nav.main-nav').addClass('stickytop');
}
else {
$('nav.main-nav').removeClass('stickytop');
}
});
});