Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

We are currently changing the appearance of the wiki to a responsive theme to eliminate switching between desktop and mobile themes. Please report any issues on the Wiki Support page

 Actions

MediaWiki

Difference between revisions of "ScrollTop.js"

From Dragon Mania Legends Wiki

m
m (Test js/css scroll on Monobook)
 
Line 1: Line 1:
 +
/* Insert Top Button after Body Content */
 +
 +
$(function() {
 +
  $('<button onclick="topFunction()" id="topBtn" title="Go to top"></button>').insertAfter('div#mw-content-text');
 +
});
 +
 
// When users scroll down 100px, show the Top button
 
// When users scroll down 100px, show the Top button
 
window.onscroll = function() {scrollFunction()};
 
window.onscroll = function() {scrollFunction()};

Latest revision as of 03:48, 14 July 2019

/* Insert Top Button after Body Content */

$(function() {
  $('<button onclick="topFunction()" id="topBtn" title="Go to top"></button>').insertAfter('div#mw-content-text');
});

// When users scroll down 100px, show the Top button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
    document.getElementById("topBtn").style.display = "block";
  } else {
    document.getElementById("topBtn").style.display = "none";
  }
}

// When users click on Top button, scroll up
function topFunction() {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
}