Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rahuldass/420e256c5d5dc08a4167 to your computer and use it in GitHub Desktop.
Save rahuldass/420e256c5d5dc08a4167 to your computer and use it in GitHub Desktop.
Shrink Navigation Bar when Scrolling down #jquery

###Shrink Navigation Bar when Scrolling down

Demo Link :- http://jsfiddle.net/rahuldass/VhXE5/


HTML

<div id="header_nav">nav here</div>

CSS

body {
    height:1000px;
    width:100%;
    background-color:#F0F0F0;
}

#header_nav {
    width:100%;
    height:100px;
    background-color:#666;
    position:fixed;
    top:0;
    left:0;
}

JavsScript

$(function(){
    $('#header_nav').data('size','big');
});

$(window).scroll(function(){
    var $nav = $('#header_nav');
    if ($('body').scrollTop() > 0) {
        if ($nav.data('size') == 'big') {
            $nav.data('size','small').stop().animate({
                height:'80px'
            }, 600);
        }
    } else {
        if ($nav.data('size') == 'small') {
            $nav.data('size','big').stop().animate({
                height:'100px'
            }, 600);
        }  
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment