Skip to content

Instantly share code, notes, and snippets.

@dansinker
Created March 23, 2012 17:29
Show Gist options
  • Save dansinker/2173030 to your computer and use it in GitHub Desktop.
Save dansinker/2173030 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
var top = $('#bookbar').offset().top - parseFloat($('#bookbar').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#bookbar').addClass('fixed');
} else {
// otherwise remove it
$('#bookbar').removeClass('fixed');
}
});
});
*******
CSS:
#bookbar.fixed {
position: fixed;
top: 0px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment