MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

Gadget:oouiup.js:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
(// Edit via Wikiplus)
(// Edit via Wikiplus)
第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;
let scrollbarWidth;
switch ("scroll") {
switch ( 'scroll' ) {
case getComputedStyle(body).overflowY:
case getComputedStyle( body ).overflowY:
scrollbarWidth = innerWidth - body.clientWidth;
scrollbarWidth = innerWidth - body.clientWidth;
break;
break;
case getComputedStyle(html).overflowY:
case getComputedStyle( html ).overflowY:
scrollbarWidth = innerWidth - html.clientWidth;
scrollbarWidth = innerWidth - html.clientWidth;
break;
break;
default:
default:
var backup = body.style.overflowY;
const backup = body.style.overflowY;
body.style.overflowY = "scroll";
body.style.overflowY = 'scroll';
scrollbarWidth = innerWidth - body.clientWidth;
scrollbarWidth = innerWidth - body.clientWidth;
body.style.overflowY = backup;
body.style.overflowY = backup;
}
}
var btnObj = new OO.ui.ButtonWidget({
const btnObj = new OO.ui.ButtonWidget( {
icon: 'collapse',
icon: 'collapse',
label: "ABC",
label: 'ABC',
title: "TIT",
title: 'TIT',
invisibleLabel: true,
invisibleLabel: true,
classes: ['backToTop']
classes: [ 'backToTop' ]
})
} );
btnObj.on("click",function() {
btnObj.on( 'click', function () {
$("html, body").animate({
$( 'html, body' ).animate( {
scrollTop: 0
scrollTop: 0
}, 120);
}, 120 );
}
}
)
);
var btn=btnObj.$element;
const $btn = btnObj.$element;
btn.appendTo('body')
$btn.appendTo( 'body' );
if (scrollbarWidth === 0) {
if ( scrollbarWidth === 0 ) {
$btn.css( 'right', '20px' );
btn.css("right", "20px"); // 修复新版 Chrome 的自动隐藏式滚动条导致的按钮被覆盖 chrome://flags/#overlay-scrollbars
}
}
$(window).on("scroll", function() {
window.onscroll = function () {
$(document).scrollTop() > 0 ? btn.fadeIn() : btn.fadeOut();
if ( document.scrollingElement.scrollTop > 0 ) {
}).scroll();
$btn.fadeIn();
} else {
});
$btn.fadeOut();
}
};
} );

2023年7月23日 (日) 17:24的版本

$( function () {
	const body = document.body,
		html = document.documentElement;
	const innerWidth = window.innerWidth;
	let scrollbarWidth;
	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: 'ABC',
		title: 'TIT',
		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();
		}
	};
} );