$(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();
});