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; }); 

jsfiddle


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -