A Pen by Malith Hettiarachchi on CodePen.
Created
January 21, 2014 11:55
-
-
Save pavsmk/8538716 to your computer and use it in GitHub Desktop.
A Pen by Malith Hettiarachchi.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="header"> | |
<h1>Animated Fixed Header (Scroll Down)</h1> | |
</div> | |
<div class="content"> | |
</div> | |
<script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var shrinkHeader = 300; | |
$(window).scroll(function() { | |
var scroll = getCurrentScroll(); | |
if ( scroll >= shrinkHeader ) { | |
$('.header').addClass('shrink'); | |
} | |
else { | |
$('.header').removeClass('shrink'); | |
} | |
}); | |
function getCurrentScroll() { | |
return window.pageYOffset || document.documentElement.scrollTop; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.header { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
background: #cc5350; | |
color:#fff; | |
z-index: 1000; | |
height: 200px; | |
overflow: hidden; | |
-webkit-transition: height 0.3s; | |
-moz-transition: height 0.3s; | |
transition: height 0.3s; | |
text-align:center; | |
line-height:160px; | |
} | |
.header.shrink { | |
height: 100px; | |
line-height:80px; | |
} | |
.header h1 | |
{ | |
font-size:30px; | |
font-weight:normal; | |
-webkit-transition: all 0.3s; | |
-moz-transition: all 0.3s; | |
transition: all 0.3s; | |
} | |
.header.shrink h1 | |
{ | |
font-size:24px; | |
-webkit-transition: all 0.3s; | |
-moz-transition: all 0.3s; | |
transition: all 0.3s; | |
} | |
.content | |
{ | |
height:2000px; | |
/*just to get the page to scroll*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment