-1

Hi,

If you take a look at this page > http://www.wikihow.com/
You'll notice the navigation bar height will be less greater when scrolled down. I want to apply this to my navigation bar using jQuery. I've found solutions on google, but people say you'll need some plugins. I think this isn't true, am I right?

Thanks.

2 Answers2

0

View my comment in this post, might be useful: Jquery if $(window) scroll down function

and to keep the div of the navigation bar on the top when scrolling you should define it

position: fixed;
Community
  • 1
  • 1
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
0

Here's the code:

$(document).scroll(function(){
   var scroll = 0;

   if (typeof window.pageYOffset !== 'undefined' ) {
      scroll = window.pageYOffset;
   }

   var d = document.documentElement;
   if (d.clientHeight) {
       scroll = d.scrollTop;
   }
   scroll = document.body.scrollTop;

   if (scroll > 100) {
      // scroll greater than 100px, decrease navigation bar height
   }else{
      // scroll less than 100px,  increase navigation bar height
   }
});

Also, You need to make navigation bar position:fixed

That's it.

Viswanath Donthi
  • 1,791
  • 1
  • 11
  • 12