Skip to content

Instantly share code, notes, and snippets.

@justinallen
Last active December 20, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinallen/6075889 to your computer and use it in GitHub Desktop.
Save justinallen/6075889 to your computer and use it in GitHub Desktop.
Floating-to-Fixed Placement Element
var topOffsetOfElement = $('#element').offset().top;
$(window).scroll(function (event) {
// get the y position of the scroll
var y = $(this).scrollTop();
// is that below the element
if (y >= top) {
// add fixed
$('#element').addClass('fixed');
} else {
// remove it
$('#element').removeClass('fixed');
}
});
@justinallen
Copy link
Author

Add positioning in CSS class fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment