StickyHeader
by Good Muyis
HTML
<div class="container">
<div class="cover-photo-container">Please scroll</div>
<div class="small-box"></div>
<div class="small-box"></div>
<div class="small-box"></div>
<div class="small-box"></div>
<div class="clear">
<div>
<div class="sticky-header">This needs to be fixed when hits top of screen</div>
</div>
CSS
body {
margin:0px;
padding:0px;
}
.clear {
clear:both;
}
.container {
height:2000px;
}
.cover-photo-container {
width:700px;
height: 100px;
margin-bottom: 20px;
background-color:red;
}
.fixed {
position: fixed;
top:0; left:0;
width: 100%; }
.small-box {
width:163px;
height:100px;
border:1px solid blue;
float:left;
}
.sticky-header {
width:700px;
height:50px;
background:orange;
postion:fixed;
}
JavaScript
$(window).scroll(function(){
if ($(window).scrollTop() >= 330) {
$('.sticky-header').addClass('fixed');
}
else {
$('.sticky-header').removeClass('fixed');
}
});