MediaWiki:Gadget-LetYouDown.js:修订间差异
外观
AnnAngela-dbot(留言 | 贡献) 代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot] 标签:由机器人或全自动脚本执行的操作 |
AnnAngela-dbot(留言 | 贡献) 代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot] 标签:由机器人或全自动脚本执行的操作 |
||
| 第9行: | 第9行: | ||
"use strict"; | "use strict"; | ||
$(() => { | |||
$( | const container = $("#mw-content-text"); | ||
const getScrollTop = () => { | |||
const headings = $("#mw-content-text .mw-parser-output > :is(h1, h2)"); | |||
return (headings.length >= 3 ? headings.last().offset().top : container.offset().top + container.outerHeight()) - 20; | return (headings.length >= 3 ? headings.last().offset().top : container.offset().top + container.outerHeight()) - 20; | ||
}; | }; | ||
let scrollTop = getScrollTop(); | |||
setInterval( | setInterval(() => { | ||
scrollTop = getScrollTop(); | scrollTop = getScrollTop(); | ||
}, 7130); | }, 7130); | ||
const btn = insertToBottomRightCorner("跳到底部").attr({ | |||
title: "跳到底部", | title: "跳到底部", | ||
id: "LetYouDown" | id: "LetYouDown", | ||
}).css({ | }).css({ | ||
"user-select": "none", | "user-select": "none", | ||
transition: "opacity .13s ease-in-out", | transition: "opacity .13s ease-in-out", | ||
order: "999" | order: "999", | ||
}).on("click", | }).on("click", () => { | ||
$("html, body").animate({ | $("html, body").animate({ | ||
scrollTop: scrollTop | scrollTop: scrollTop, | ||
}, 130); | }, 130); | ||
}); | }); | ||
const $document = $(document); | |||
$(window).on("resize", | $(window).on("resize", () => { | ||
scrollTop = getScrollTop(); | scrollTop = getScrollTop(); | ||
}).on("scroll", | }).on("scroll", () => { | ||
btn.css("opacity", $document.scrollTop() < scrollTop ? ".6" : "0"); | btn.css("opacity", $document.scrollTop() < scrollTop ? ".6" : "0"); | ||
}).trigger("scroll"); | }).trigger("scroll"); | ||
}); | }); | ||
/* </pre> */ | /* </pre> */ | ||
2025年7月24日 (四) 20:27的版本
/**
* -------------------------------------------------------------------------
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
* -------------------------------------------------------------------------
*/
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/LetYouDown/Gadget-LetYouDown.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}';
/* <pre> */
"use strict";
$(() => {
const container = $("#mw-content-text");
const getScrollTop = () => {
const headings = $("#mw-content-text .mw-parser-output > :is(h1, h2)");
return (headings.length >= 3 ? headings.last().offset().top : container.offset().top + container.outerHeight()) - 20;
};
let scrollTop = getScrollTop();
setInterval(() => {
scrollTop = getScrollTop();
}, 7130);
const btn = insertToBottomRightCorner("跳到底部").attr({
title: "跳到底部",
id: "LetYouDown",
}).css({
"user-select": "none",
transition: "opacity .13s ease-in-out",
order: "999",
}).on("click", () => {
$("html, body").animate({
scrollTop: scrollTop,
}, 130);
});
const $document = $(document);
$(window).on("resize", () => {
scrollTop = getScrollTop();
}).on("scroll", () => {
btn.css("opacity", $document.scrollTop() < scrollTop ? ".6" : "0");
}).trigger("scroll");
});
/* </pre> */