Skip to content

Instantly share code, notes, and snippets.

@akb
Created August 26, 2011 14:39
Show Gist options
  • Select an option

  • Save akb/1173540 to your computer and use it in GitHub Desktop.

Select an option

Save akb/1173540 to your computer and use it in GitHub Desktop.
scrollbar thing
window.onscroll = function () {
if (!docked && (menu.offsetTop - scrollTop() < 0)) {
menu.style.top = 0;
menu.style.position = 'fixed';
menu.className = 'docked';
docked = true;
} else if (docked && scrollTop() <= init) {
menu.style.position = 'absolute';
menu.style.top = init + 'px';
menu.className = menu.className.replace('docked', '');
docked = false;
}
};
function scrollTop() {
return document.body.scrollTop || document.documentElement.scrollTop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment