Gadget:oouiup.js:修订间差异

(// Edit via Wikiplus)
(// Edit via Wikiplus)
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
$(function() {
$( function () {
    var body = document.body,
const body = document.body,
        html = document.documentElement;
html = document.documentElement;
    var innerWidth = window.innerWidth;
const innerWidth = window.innerWidth;
    var scrollbarWidth;
var scrollbarWidth;
    switch ("scroll") {
if($(".backToTop").length > 0) { // 已经加载了仿论坛版本
        case getComputedStyle(body).overflowY:
return;
            scrollbarWidth = innerWidth - body.clientWidth;
}
            break;
switch ( 'scroll' ) {
        case getComputedStyle(html).overflowY:
case getComputedStyle( body ).overflowY:
            scrollbarWidth = innerWidth - html.clientWidth;
scrollbarWidth = innerWidth - body.clientWidth;
            break;
break;
        default:
case getComputedStyle( html ).overflowY:
            var backup = body.style.overflowY;
scrollbarWidth = innerWidth - html.clientWidth;
            body.style.overflowY = "scroll";
break;
            scrollbarWidth = innerWidth - body.clientWidth;
default:
            body.style.overflowY = backup;
const backup = body.style.overflowY;
    }
body.style.overflowY = 'scroll';
var btnObj = new OO.ui.ButtonWidget({
scrollbarWidth = innerWidth - body.clientWidth;
  icon: 'collapse',
body.style.overflowY = backup;
  label: "ABC",
}
  title: "TIT",
const btnObj = new OO.ui.ButtonWidget( {
  invisibleLabel: true,
icon: 'collapse',
  classes: ['backToTop']
label: '返回顶部',
})
title: '返回顶部',
btnObj.on("click",function() {
invisibleLabel: true,
                $("html, body").animate({
classes: [ 'backToTop' ]
                    scrollTop: 0
} );
                }, 120);
btnObj.on( 'click', function () {
            }
$( 'html, body' ).animate( {
)
scrollTop: 0
var btn=btnObj.$element;
}, 120 );
btn.appendTo('body')
}
    if (scrollbarWidth === 0) {
);
        btn.css("right", "20px"); // 修复新版 Chrome 的自动隐藏式滚动条导致的按钮被覆盖 chrome://flags/#overlay-scrollbars
const $btn = btnObj.$element;
    }
$btn.appendTo( 'body' );
    $(window).on("scroll", function() {
if ( scrollbarWidth === 0 ) {
        $(document).scrollTop() > 0 ? btn.fadeIn() : btn.fadeOut();
$btn.css( 'right', '20px' );
    }).scroll();
}
});
window.onscroll = function () {
if ( document.scrollingElement.scrollTop > 0 ) {
$btn.fadeIn();
} else {
$btn.fadeOut();
}
};
window.onscroll();
} );

2023年7月30日 (日) 18:18的最新版本

$( function () {
	const body = document.body,
		html = document.documentElement;
	const innerWidth = window.innerWidth;
	var scrollbarWidth;
	if($(".backToTop").length > 0) { // 已经加载了仿论坛版本
		return;
	}
	switch ( 'scroll' ) {
		case getComputedStyle( body ).overflowY:
			scrollbarWidth = innerWidth - body.clientWidth;
			break;
		case getComputedStyle( html ).overflowY:
			scrollbarWidth = innerWidth - html.clientWidth;
			break;
		default:
			const backup = body.style.overflowY;
			body.style.overflowY = 'scroll';
			scrollbarWidth = innerWidth - body.clientWidth;
			body.style.overflowY = backup;
	}
	const btnObj = new OO.ui.ButtonWidget( {
		icon: 'collapse',
		label: '返回顶部',
		title: '返回顶部',
		invisibleLabel: true,
		classes: [ 'backToTop' ]
	} );
	btnObj.on( 'click', function () {
		$( 'html, body' ).animate( {
			scrollTop: 0
		}, 120 );
	}
	);
	const $btn = btnObj.$element;
	$btn.appendTo( 'body' );
	if ( scrollbarWidth === 0 ) {
		$btn.css( 'right', '20px' );
	}
	window.onscroll = function () {
		if ( document.scrollingElement.scrollTop > 0 ) {
			$btn.fadeIn();
		} else {
			$btn.fadeOut();
		}
	};
	window.onscroll();
} );