javascript - Add and remove Bootstrap navbar class depending on scroll position -


i'm building website, begins static navbar after scrolling down (500px) function removes class "navbar-static-top" , adds "navbar-fixed-top". works correctly. want make change static when user scroll top.. couldn't find online, ii've tried uses jquery 'hasclass()' function, doesn't work either...any ideas?

have now..

   $(window).scroll(function() {     $('#navbarmain').each(function(){     var imagepos = $(this).offset().top;      var topofwindow = $(window).scrolltop();          if (imagepos > topofwindow-500) {             $(this).removeclass("navbar-static-top");             $(this).addclass("navbar-fixed-top");         }      }); });  

i'm using this

$(window).scroll(function() {     var nav = $('#navbarmain');     var top = 200;     if ($(window).scrolltop() >= top) {          nav.addclass('fixed');      } else {         nav.removeclass('fixed');     } }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -