javascript - Show/hide navigation on scroll position -


this jquery show navigation menu when scroll page 0px (in right-way). trying show after 200px (on page scroll-up), means not showing right way, want show , hide after 200px when scroll page.

jquery: fiddle

// script lastscroll = 0; $(window).on('scroll',function() {         var scroll = $(window).scrolltop();     if(scroll === 0){         $(".nav").removeclass("darkheader");     } else if(lastscroll - scroll > 0) {         $(".nav").addclass("darkheader");     } else {         $(".nav").removeclass("darkheader");     }     lastscroll = scroll; }); 

html:

<div class="nav"> sticky top navigation bar </div> <div class="wrap"> <h3>some filler text</h3> bacon ipsum dolor sit amet mollit ball tip occaecat brisket cupidatat meatball capicola. capicola rump turducken, elit shankle cupidatat pastrami duis fatback. sint occaecat kielbasa labore pastrami corned beef. sunt swine bacon, fugiat dolor aute anim jerky nostrud et venison shankle consectetur boudin landjaeger. pork chop sed turkey aute, duis corned beef pariatur short loin proident culpa. capicola filet mignon fugiat corned beef shank ea, commodo doner adipisicing eu salami. doner laboris pariatur beef ribs non id. andouille eu meatball consectetur ham hock. ea dolore cillum cow pork loin aliquip leberkas id est corned beef dolore t-bone. in salami jerky cupidatat et. </div> 

any advice? example fiddle.
thanks in advance.

#one of way have found:

// script     var lastscroll = 0;     var scrollupstart = 0;     $(window).on('scroll',function() {          var scroll = $(window).scrolltop();         if(scroll === 0){             // @ top             $(".nav").removeclass("darkheader");         } else if(lastscroll > scroll) {             // scrolling              // check if have started scrolling             if (scrollupstart < scroll) {                 // if started scrolling up, set 'marker'                 scrollupstart = scroll;             }              if (scrollupstart - scroll > 200) {                 $(".nav").addclass("darkheader");             }          } else {             scrollupstart = 0;             // scrolling down             $(".nav").removeclass("darkheader");         }         lastscroll = scroll;     }); 

example fiddle :)


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -