javascript - Prevent adding class without browser scroll -
this js add class while scroll browser page. problem after scroll browser top of page .darkheader
class not remove, means want remove class after page scroll top.
js
lastscroll = 0; $(window).on('scroll',function() { var scroll = $(window).scrolltop(); if(lastscroll - scroll > 0) { $(".nav").addclass("darkheader"); } else { $(".nav").removeclass("darkheader"); } lastscroll = scroll; });
jsfiddle >>
how remove .darkheader
class after page has scroll on top of page/head? how prevent adding class without browser scrolling?
you add condition checks if scrolling @ top of page, , removes class this:
if(scroll === 0){ $(".nav").removeclass("darkheader"); } else if(lastscroll - scroll > 0) { $(".nav").addclass("darkheader"); } else { $(".nav").removeclass("darkheader"); }
Comments
Post a Comment