Hopefully this helps you out.
<style>
/* Initial Styling Applied Here */
header{
}
/* Wanted Styling While Fixed */
header.fixed{
position:fixed;
top:0;
z-index:100;
}
</style>
Create your header in HTML (This can be any container, really)
<header></header>
Create your event handler in JS/jQuery
<script>
// On Scroll
$(window).scroll(function(){
// If we have scrolled more than 10px
if($(document).scrollTop() > 10){
// Add class "fixed" to header element
$('header').addClass('fixed');
// Otherwise
}else{
// If header already has "fixed" class
if($('header').hasClass('fixed')){
// Remove said class
$('header').removeClass('fixed');
}
}
});
</script>