回到页顶按钮会将回到页顶的按钮添加到页面右下角(现代化版本)或工具栏右侧(旧版)。
Installation
自定义
如果您想要调整向上滚动的速度或向下滚动的数量,您必须为按钮的显示设置和其他选项做大量工作,请在引用脚本到您(的全域JS或者)社区的MediaWiki:Common.js页面之前添加以下内容。
现代化
按钮有两个变种,现代化样式和旧版样式。按钮默认启用旧版样式,如果要启用现代化样式,请添加以下代码。
window.BackToTopModern = true;
箭头图标
如果要使用按钮的旧变体,且要显示的是箭头图标而不是按钮,则可以使用以下代码:
window.BackToTopArrow = true;
按钮文本
按钮文本将自动以用户使用语言显示。但是如果要更改按钮文本,可以效仿以下代码进行自定义。
window.BackToTopText = "新文本";
滚动速度
要调整滚动速度,请添加以下代码:
window.BackToTopSpeed = number;
其中number是滚动时间,以毫秒为单位。数字越大,滚动速度越慢;数字越小,滚动速度越快。默认值为600。
按钮外观
要调整“深度”,您必须添加以下代码设置按钮达成出现和消失的位置:
window.BackToTopStart = number;
其中number是按钮在下方出现之前距页面的距离,以像素为单位。较高的数字会让您还要下滑屏幕,按钮才会出现。默认值为800。
按钮格式
您也可以使用CSS随意设置按钮的格式。例如:
/* Back-to-top button format */
#BackToTopBtn div {
opacity: 0.7;
transition: .5s;
}
#BackToTopBtn div:hover {
opacity: 1;
}
上面的CSS规则将使按钮变为半透明,直到鼠标悬停。仅适用于按钮的现代化样式变种。
/* Back-to-top button format */
#backtotop button{
background: none;
background-color: transparent;
color: white;
border: none;
}
#backtotop button:hover {
text-decoration: underline;
}
上面的CSS规则将使按钮看起来像一个简单的链接。仅适用于按钮的旧版样式变种。
禁用按钮淡入淡出效果
要禁用按钮淡入淡出效果,请添加以下代码:
window.BackToTopFade = 0;
Using configuration options with Fandom Developers Wiki scripts
The instructions on this page describe how to use configuration options with a script. Here on the Fandom Developers Wiki, many scripts provide optional configuration settings as a mean to alter or enhance the default behavior of the script. When installing configuration options in your JavaScript file, please note that they need to go above the import statement in order to work — unless the directions say otherwise. In case MediaWiki:ImportJS is used to load the scripts, it will be executed last.
// 1. AjaxRC import statement
importArticles({
type: 'script',
articles: [
'u:dev:MediaWiki:AjaxRC.js'
]
});
// 2. AjaxRC configuration option
window.ajaxRefresh = 30000;
// 1. AjaxRC configuration option
window.ajaxRefresh = 30000;
// 2. AjaxRC import statement
importArticles({
type: 'script',
articles: [
'u:dev:MediaWiki:AjaxRC.js'
]
});
要重新启用淡入淡出效果,只需从JS页面中删除此行即可。按钮的淡入淡出效果默认启用。