Created
February 21, 2011 21:22
-
-
Save danott/837729 to your computer and use it in GitHub Desktop.
Apple Cart style scroll lock
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
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
/* | |
* Plugin developed by Dan Bentley | |
* @dan_bentley | |
* | |
* @danott: Found on http://csswizardry.com/. No licensing information provided, so I will use it | |
* unless told otherwise by it's author. | |
*/ | |
(function($) { | |
var defaults = {}; | |
$.fn.fixedscroll = function(opts) { | |
var options = $.extend(defaults, opts); | |
var el = $(this); | |
if (el.css('position') !== 'fixed') return; | |
var lockPosition = options.lockElement.offset().top - el.outerHeight(); | |
var offsetTop = options.offset.top || 0; | |
$(window).bind('load scroll', function(e) { | |
if ($(window).scrollTop() + offsetTop >= lockPosition) { | |
el.css({ | |
position: "absolute", | |
top: lockPosition | |
}); | |
} else { | |
el.css({ | |
position: "fixed", | |
top: offsetTop | |
}); | |
} | |
}); | |
}; | |
})(jQuery); | |
$(document).ready(function() { | |
$('#header > div').fixedscroll({ | |
'offset': {'top': 75}, | |
'lockElement': $('#comments') | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment