Difference between revisions of "MediaWiki:Common.js"
From PCGamingWiki, the wiki about fixing PC games
Masked Turk (talk | contribs) m (Alternate script test) |
Masked Turk (talk | contribs) m (Another test) |
||
Line 1: | Line 1: | ||
/* Below: necessary for the Beginner's Guide template */ | /* Below: necessary for the Beginner's Guide template */ | ||
− | |||
var $sidebar = $("#guide-nav"), | var $sidebar = $("#guide-nav"), | ||
$window = $(window), | $window = $(window), | ||
offset = $sidebar.offset(), | offset = $sidebar.offset(), | ||
topPadding = 15; | topPadding = 15; | ||
− | + | ||
− | + | $(window).scroll(function() { | |
− | + | if( $sidebar.scrollTop() >= offset.top ) { | |
− | $sidebar. | + | if( !fixed ) { |
− | + | fixed = true; | |
− | + | $sidebar.css({position:'fixed',top:20}); // Or set top:20px; in CSS | |
− | } else { | + | } // It won't matter when static |
− | $sidebar. | + | } else { |
− | + | if( fixed ) { | |
− | + | fixed = false; | |
+ | $sidebar.css({position:'static'}); | ||
} | } | ||
− | } | + | } |
}); | }); | ||
/* end Beginners Guide script */ | /* end Beginners Guide script */ |
Revision as of 21:25, 29 April 2012
/* Below: necessary for the Beginner's Guide template */ var $sidebar = $("#guide-nav"), $window = $(window), offset = $sidebar.offset(), topPadding = 15; $(window).scroll(function() { if( $sidebar.scrollTop() >= offset.top ) { if( !fixed ) { fixed = true; $sidebar.css({position:'fixed',top:20}); // Or set top:20px; in CSS } // It won't matter when static } else { if( fixed ) { fixed = false; $sidebar.css({position:'static'}); } } }); /* end Beginners Guide script */