Skip to content

Instantly share code, notes, and snippets.

@Kjuly
Last active September 27, 2015 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kjuly/1248387 to your computer and use it in GitHub Desktop.
Save Kjuly/1248387 to your computer and use it in GitHub Desktop.
Auto change the topbar position type depend on scrollbar
/*!
* Author: Kjuly(Kj Yu)
* Date: 09/29/2011
* Feel free to use this code snippet. ;)
*
*/
$(function() {
$(window).scroll(function() {
if ($(this).scrollTop() >= 100) { // The Logo's above the topbar is 100px
$('div.topbar').css({
position:"fixed", // After the logo area disappear, fix the topbar at top:0
'top':0,
'left':0,
'right':0
});
} else {
$('div.topbar').css({'position':'relative'}); // Just below the logo area.
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment