Animated Header on Page Scroll

Posted By : Gaurav Arora | 30-Dec-2016

Hi, As we all know that animated header has become very common among websites. They can be simple created by including animated header's js files. But we can easily create that thing without including any js file. But with the help of some jquery function that will detect the page scroll.

We will start by including our HTML part.

Header

After that we will include some css to animate our header.

section{
  width: 100%;
  min-height: 1000px;
  float: left;
}
header{
  width: 100%;
  padding: 30px;
  float: left;
  background: #303030;
  text-align: center;
  color: #fff;
  transition: all ease-in 0.2s;
}
header.fix{
  position: fixed;
  padding: 20px;
  animation-name: animate-header;
  animation-duration: 0.5s; 
}
header h1{
  margin:0;
  padding: 0;
  font-size: 30px;
  font-weight: normal;
  transition: all ease-in 0.2s;
}
@keyframes animate-header{
  from{
    transform: translateY(-100%);
  }
  to{
    transform: translateY(0);
  }
}
 

Now we will add window.scroll(function() so that we can add and remove our animated class on scroll

$(window).scroll(function(){
	if($(this).scrollTop() > 100){
  	$("header").addClass("fix");
  }else{
  	$("header").removeClass("fix");
  }
});
 

In this way we can animate our header on scroll

About Author

Author Image
Gaurav Arora

Gaurav is an experienced UI developer with experience and capabilities to build compelling UI's for Web and Mobile Applications.

Request for Proposal

Name is required

Comment is required

Sending message..