Gadget:oouiup.js

Litwak913留言 | 贡献2023年7月23日 (日) 17:09的版本 (// Edit via Wikiplus)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
$(function() {
    var body = document.body,
        html = document.documentElement;
    var innerWidth = window.innerWidth;
    var scrollbarWidth;
    switch ("scroll") {
        case getComputedStyle(body).overflowY:
            scrollbarWidth = innerWidth - body.clientWidth;
            break;
        case getComputedStyle(html).overflowY:
            scrollbarWidth = innerWidth - html.clientWidth;
            break;
        default:
            var backup = body.style.overflowY;
            body.style.overflowY = "scroll";
            scrollbarWidth = innerWidth - body.clientWidth;
            body.style.overflowY = backup;
    }
var btnObj = new OO.ui.ButtonWidget({
  icon: 'collapse',
  label: "ABC",
  title: "TIT",
  invisibleLabel: true,
  classes: ['backToTop']
})
var btn=btnObj.$element;
btn.appendTo('body')
    if (scrollbarWidth === 0) {
        btn.css("right", "20px"); // 修复新版 Chrome 的自动隐藏式滚动条导致的按钮被覆盖 chrome://flags/#overlay-scrollbars
    }
    $(window).on("scroll", function() {
        $(document).scrollTop() > 0 ? btn.fadeIn() : btn.fadeOut();
    }).scroll();
});