Skip to content

Instantly share code, notes, and snippets.

@ThiefMaster
Created September 5, 2012 00:26
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 ThiefMaster/3628490 to your computer and use it in GitHub Desktop.
Save ThiefMaster/3628490 to your computer and use it in GitHub Desktop.
sticky scroller from stackexchange websites
function moveScroller() {
var width = $('#scroller').width();
var move = function () {
var st = $(window).scrollTop();
var ot = $('#scroller-anchor').offset().top;
var s = $('#scroller');
if (st > ot) {
if (s.height() > $(window).height()) {
s.css({ 'position': 'fixed', 'top': '', 'bottom': '0px', 'width': width });
} else {
s.css({ 'position': 'fixed', 'top': '0px', 'bottom': '', 'width': width });
}
}
else if (st <= ot)
s.css({ 'position': 'relative', 'top': '', 'bottom': '' });
};
$(window).scroll(move).resize(move);
move();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment