MediaWiki:Gadget-snapToTop.js: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
Bongolium500 (talk | contribs) No edit summary |
Bongolium500 (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
'use strict'; | 'use strict'; | ||
var $icon = 'https://tardis.wiki/images/Tardis_Images/3/3e/Back_to_top_button_image.png'; | var $icon = 'https://tardis.wiki/w/images/Tardis_Images/3/3e/Back_to_top_button_image.png'; | ||
$icon = $('<img>', { | $icon = $('<img>', { |
Latest revision as of 15:03, 31 July 2024
/* From https://fallout.wiki/wiki/MediaWiki:Common.js under CC B-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/)
* @rev 4 (2021-05-08)
* @author Kwj2772
* @contributor Perhelion */
$(function () {
'use strict';
var $icon = 'https://tardis.wiki/w/images/Tardis_Images/3/3e/Back_to_top_button_image.png';
$icon = $('<img>', {
src: $icon,
id: 'scrollUpButton',
class: 'noprint'
}).css({
}).on('click', function () {
// Move to the top of the page
$('html, body').animate({ scrollTop: 0 }, 660);
}).on('mouseenter mouseleave', function (e) {
this.style.opacity = e.type === 'mouseenter' ? 1 : 0.7;
}).appendTo('body');
$(window).on('scroll', function () {
// Fade out if you reach the top of the page
if ($(this).scrollTop() > 80) $icon.fadeIn('fast');
else $icon.fadeOut('slow');
});
}());