MediaWiki:Gadget-ScrollUpButton.js:修订间差异
删除的内容 添加的内容
创建页面,内容为“→* * Copyright (c) 2021-present, 安忆. * * @author 安忆 [[zh:U:安忆]] * @file scrollUpButton.js * @license GPL v3: $(function scrollUpButton() { var $window = $(window); var scrollButtonIcon = '//zybkcn.com/w/images/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg'; if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) { scrollButtonIcon = '//zybkcn.com/w/images/5/59/Font_Awesome_5_regular_arrow…” |
重构:节流优化、移除 dead code、修复动画堆积 |
||
第8行:
$(function scrollUpButton() {
var $window = $(window);
var
var visible = false;
function scrollTo(h) {
$('html, body').stop(true, true).animate({ scrollTop: h }, 500);
}
function makeBtn(id, onClick, extraCss) {
return $('<img>')
.addClass('noprint')
.attr({ id: id, src: icon, draggable: 'false' })
display: 'none',
position: 'fixed',
right: '18px',
opacity: '0.7',
width: '40px',
...extraCss
})
.on('mouseenter', function () { this.style.opacity = '1'; })
.on('mouseleave', function () { this.style.opacity = '0.7'; })
.on('click', onClick)
.appendTo(document.body);
}
var $up = makeBtn('scrollUpBtn', function () { scrollTo(0); }, { bottom: '85px' });
var $down = makeBtn('scrollDownBtn', function () {
scrollTo(($(document).height() || 0) - ($window.height() || 0));
}, { bottom: '45px', transform: 'rotate(180deg)' });
var $elements = $up.add($down);
$elements.css('left', px ? px + 'px' : 'unset');
$elements.
}
var isVector2022 = mw.config.get('skin') === 'vector-2022';
var
function onWidthChange(e) {
setRight(e.matches ? 8 : 18);
}
}
if (isVector2022) {
try {
} catch (
}
onWidthChange(mql);
}
var
if (y > 200 && !visible) {
visible = true;
$elements.fadeIn(300);
} else if (y <= 200 && visible) {
}
if (
(mw.config.get('wgGEHelpPanelEnabled') && $('#mw-ge-help-panel-cta-button').length) ||
$('#cat_a_lot').length ||
$('#proveit').length ||
$('.wordcount').length
) {
setLeft(10);
} else {
}
}
var ticking = false;
$window.on('scroll', function () {
if (!ticking) {
requestAnimationFrame(function () {
onScroll();
ticking = false;
});
ticking = true;
}
});
onScroll();
});
| |||