Last active
December 20, 2015 05:09
-
-
Save justinallen/6075889 to your computer and use it in GitHub Desktop.
Floating-to-Fixed Placement Element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add positioning in CSS class
fixed
.