Created
June 12, 2014 20:18
-
-
Save codenamezjames/c534ddec340841508d79 to your computer and use it in GitHub Desktop.
add the class "magic-floating-stuff" to any bootstrap column and it will follow your screen when you pass it
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
$(function(){ | |
var MFS = $('.magic-floating-stuff') | |
var ogScrollTop = $('body').offset().top, | |
ogElementOffset = MFS.offset().top, | |
ogDistance = (ogElementOffset - ogScrollTop); | |
MFSheight = MFS.outerHeight() | |
documentHeight = $(document).outerHeight() | |
$('body').change(function(){ | |
MFSheight = MFS.outerHeight() | |
}); | |
$(window).on('scroll', function(){ | |
var offsetTop = $('body').offset().top, | |
elementOffset = MFS.offset().top, | |
distance = (elementOffset - offsetTop); | |
var scrollTop = $(window).scrollTop() | |
console.log(documentHeight) | |
if(scrollTop > ogDistance ){ | |
if(scrollTop < documentHeight - MFSheight){ | |
MFS.css({"position":"relative","top": scrollTop- ogDistance }) | |
} | |
}else{ | |
MFS.css({"position":"relative","top": 0 }) | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment