MediaWiki:Gadget-stickyHeader.js: Difference between revisions

From Official Gamemode 4 Wiki
Jump to navigation Jump to search
(Created page with "→‎* * @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'); if ('ext.gadget.fixedWidth' in mw.loader.moduleRegistry && mw.loader.moduleRegistry['ext.gadget.fixedWidth'].state === 'ready') { stickyTo...")
 
m (what does it look like if it's not fixed width)
 
Line 7: Line 7:
     $('<div id="stickyTopBack"></div>').appendTo('#stickyTop');
     $('<div id="stickyTopBack"></div>').appendTo('#stickyTop');
     var stickyTop = $('#stickyTop');
     var stickyTop = $('#stickyTop');
    if ('ext.gadget.fixedWidth' in mw.loader.moduleRegistry && mw.loader.moduleRegistry['ext.gadget.fixedWidth'].state === 'ready') {
    stickyTop.addClass('fixedWidth');
    }
     var nsTop = $('#p-namespaces').offset().top;
     var nsTop = $('#p-namespaces').offset().top;



Latest revision as of 06:22, 3 March 2024

/*
 * 
 * @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);
});