Header hide on scroll

Posted By : Balraj Singh | 30-Jun-2015

Nowadays header/footer hide if scroll down is a common style. this style make your website beautiful and hope this article also make easy development for this.

 

The HTML

<header>Header</header>
<main>Content</main>
<footer>footer</footer>

 

The CSS

body{
	padding-top:50px; /* equal to header height */
}
header{
	background:#000;
	width:100%;
	height:50px;
	transition: top 0.7s ease-in;
	position:fixed;
	left:0;
	top:0;
}
.hide-header{
	top: -50px; /* equal to header height */
}

 

The jQuery

var lastScrollTop = 0;

$(window).scroll(function() {

    var st = $(this).scrollTop();

    if (st > lastScrollTop){

    	$('header').addClass('hide-header');

    } else {

    	$('header').removeClass('hide-header');

    }

    lastScrollTop = st;

});

THANKS

 

About Author

Author Image
Balraj Singh

Balraj is a creative UI designer with experience and capabilities to build compelling UI designs for Web and Mobile Applications. Balraj likes playing tech Quiz and loves bike riding.

Request for Proposal

Name is required

Comment is required

Sending message..