Scroll to top button

Adds a button to scroll to the top of the page

当前为 2024-05-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Scroll to top button
// @version      0.1
// @description  Adds a button to scroll to the top of the page
// @author       Bins
// @license      MIT
// @match        *://*/*
// @grant        none
// @namespace https://greasyfork.org/users/757542
// ==/UserScript==

(function() {
    'use strict';

    // Create the button
    var button = document.createElement("button");
    button.innerHTML = "⬆"; // Unicode for up arrow
    button.style.position = "fixed";
    button.style.bottom = "20px";
    button.style.right = "20px";
    button.style.zIndex = "9999";
    button.style.fontSize = "24px";
    button.style.width = "50px";
    button.style.height = "50px";
    button.style.backgroundColor = "#4CAF50";
    button.style.border = "none";
    button.style.color = "white";
    button.style.textAlign = "center";
    button.style.textDecoration = "none";
    button.style.borderRadius = "50%";
    button.style.boxShadow = "0 2px 5px 0 rgba(0,0,0,0.26),0 2px 10px 0 rgba(0,0,0,0.16)";
    button.style.transition = "background-color 0.3s";

    // Change color on hover
    button.onmouseover = function() {
        button.style.backgroundColor = "#45a049";
    }
    button.onmouseout = function() {
        button.style.backgroundColor = "#4CAF50";
    }

    // Add the button to the body of the document
    document.body.appendChild(button);

    // When the button is clicked, scroll to the top of the page
    button.addEventListener ("click", function() {
        window.scrollTo({top: 0, behavior: 'smooth'});
    });
})();