MediaWiki:Gadget-stickyHeader.js

From Official Gamemode 4 Wiki
Revision as of 06:22, 3 March 2024 by Epyon (talk | contribs) (what does it look like if it's not fixed width)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
 * 
 * @see Based on https://minecraft.wiki/w/MediaWiki:Gadget-stickyHeader.js
 */
$(function() {
    $('#left-navigation, #right-navigation').wrapAll('<div id="stickyTop"></div>').wrapAll('<div id="stickyTopFlex"></div>');
    $('<div id="stickyTopBack"></div>').appendTo('#stickyTop');
    var stickyTop = $('#stickyTop');
    var nsTop = $('#p-namespaces').offset().top;

    function sticky() {
	    var scrollTop = $(window).scrollTop();
	
	    if (scrollTop > nsTop) { 
	        stickyTop.addClass('stick');
	    } else {
	        stickyTop.removeClass('stick'); 
	    }
    };

    sticky();

    $(window).scroll(sticky);
});