javascript - Add Class only on browser Scroll Up -
there way add class when scroll browser page.
problem filide>>
js
$(window).scroll(function() { var scroll = $(window).scrolltop(); if (scroll <= 100) { $(".nav").addclass("darkheader"); } else { $(".nav").removeclass("darkheader"); } });
problem js add class when scroll-down page. want add class when scroll browser , after when scroll down class remove.
see example demo>>
if want know whether user has scrolled or down need track of last scroll position. check if new scroll position greater or less position. can set classes accordingly
// script lastscroll = 0; $(window).on('scroll',function() { var scroll = $(window).scrolltop(); if(lastscroll - scroll > 0) { $(".nav").addclass("darkheader"); } else { $(".nav").removeclass("darkheader"); } lastscroll = scroll; });
Comments
Post a Comment