Difference between revisions of "MediaWiki:Vector.js"

From TerraFirmaCraft Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for users using the Vector skin */
 
/* Any JavaScript here will be loaded for users using the Vector skin */
  
// Cache selectors outside callback for performance.
+
function sticky_relocate() { 
var $window = $(window),
+
    var window_top = $(window).scrollTop(); 
  $stickyEl = $('#p-googleadsense'),
+
    var div_top = $('#mw-page-base').offset().top; 
  elTop = $stickyEl.offset().top;
+
    if (window_top > div_top) { 
 +
        $('#p-googleadsense').addClass('sticky'); 
 +
    } else { 
 +
        $('#p-googleadsense').removeClass('sticky');
 +
    } 
 +
  
$window.scroll(function() {
+
$(function () {
$stickyEl.toggleClass('sticky', $window.scrollTop() > elTop);
+
    $(window).scroll(sticky_relocate)
 +
    sticky_relocate();
 
});
 
});

Revision as of 00:03, 21 July 2016

/* Any JavaScript here will be loaded for users using the Vector skin */

function sticky_relocate() {  
    var window_top = $(window).scrollTop();  
    var div_top = $('#mw-page-base').offset().top;  
    if (window_top > div_top) {  
        $('#p-googleadsense').addClass('sticky');  
    } else {  
        $('#p-googleadsense').removeClass('sticky');  
    }  
}  

$(function () {  
    $(window).scroll(sticky_relocate);  
    sticky_relocate();  
});