Created
March 10, 2009 13:29
-
-
Save shadowhand/76893 to your computer and use it in GitHub Desktop.
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 jump = $(this); | |
var size = jump.height(); | |
var _min = parseInt(jump.offset().top); | |
var _max = jump.parent().parent().height(); | |
var _win = $(window); | |
// Callback for scrolling | |
var callback = function() | |
{ | |
// Get the current scroll offset | |
var _cur = _win.scrollTop(); | |
if (_cur > _max) | |
{ | |
// Make the jump menu stay within the parent | |
jump.stop().animate({ marginTop: _max - size }, 200); | |
} | |
else if (_cur > _min) | |
{ | |
// Make the jump menu follow scrolling | |
jump.stop().animate({ marginTop: _cur - _min }, 200); | |
} | |
else | |
{ | |
// Just place the jump menu at the top | |
jump.stop().css('margin-top', 0); | |
} | |
}; | |
var timer = null; | |
// Run the callback | |
callback(); | |
$(window).scroll(function() | |
{ | |
// Stop the current timer | |
if (timer) clearTimeout(timer); | |
// Create a new timer | |
setTimeout(callback, 20); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment