在页面添加返回顶部按钮

原文:https://blog.csdn.net/insgo/article/details/113799700

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ==UserScript==
// @name totop
// @namespace http://unamerrr.net/
// @version 0.1
// @match *://*/*
// @description 返回顶部
// @author unamerrr
// @grant none
// ==/UserScript==
(function() {
'use strict';
var toTopBtn = document.createElement('button') toTopBtn.innerHTML = "返回顶部"toTopBtn.className = "a-b-c-d-toTop"toTopBtn.onclick = function(e) {
scrollTo(0, 0)
}
var body = document.body
var style = document.createElement('style') style.id = "a-b-c-d-style"
var css = `.a - b - c - d - toTop {
position: fixed;
bottom: 10 % ;
right: 5 % ;
width: 50px;
height: 50px;
border - radius: 50 % ;
font - size: 15px;
z - index: 999;
cursor: pointer;
font - size: 12px;
overflow: hidden;
}`
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
body.appendChild(toTopBtn) body.appendChild(style)
// Your code here...
})();

在页面添加返回顶部按钮
https://roachlin.github.io/2021-06-19-top-button/
作者
RoachLin
发布于
2021年6月19日
许可协议