Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ever seen a sticky header that sticks to the top of window when scrolled?
var msie6 = $.browser == 'msie' && $.browser.version < 7;
if (!msie6) {
// 'bar' is the id of the box which needs to be fixed
var top = $('#bar').offset().top - parseFloat($('#bar').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
var y = $(this).scrollTop();
if (y >= top) {
// if so, add the fixed class
else {
// otherwise remove it
/* In the css file you just need to add
.fixed {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.