🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/05 06:21:25
🔄 下次更新时间:2026/01/05 07:21:25
手动刷新缓存

回到顶部

平时隐藏,鼠标经过页面右端 距离页面top 80%时,会显示按键,点击触发回到顶部

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         回到顶部
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  平时隐藏,鼠标经过页面右端 距离页面top 80%时,会显示按键,点击触发回到顶部
// @author       Candy.
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
          //创建盒子
    var candy_div1 = document.createElement("div");
    document.body.appendChild(candy_div1);
    candy_div1.className = 'candy_div1';
    var candy_div2 = document.createElement('div');
    candy_div1.appendChild(candy_div2);
    candy_div2.className = 'candy_div2';

    //鼠标经过显示图标,否则隐藏
    candy_div1.onmouseenter = function () {
      candy_div1.style.cssText = 'background: rgba(0, 0, 0, 0.1);';
      candy_div2.style.cssText = 'border-bottom-color: rgba(0, 0, 0, 0.4);';
    }
    candy_div1.onmouseleave = function () {
      candy_div1.style.cssText = 'background: rgba(0, 0, 0, 0);'
      candy_div2.style.cssText = 'border-bottom-color: rgba(0, 0, 0, 0);'
    }


    //回到顶部
    candy_div1.onclick = function () {
      if (timerID_1) {
        clearInterval(timerID_1);
      }
      var top_1 = document.documentElement.scrollTop;
      var target_1 = 0;
      var step = 30;
      var timerID_1 = setInterval(function () {

        if (top_1 > target_1) {
          top_1 = top_1 - step;
          document.documentElement.scrollTop = top_1;
        } else {
          clearInterval(timerID_1);
        }

      }, 1);
    }

    //添加CSS
    function addCSS(cssText) {
      var style = document.createElement('style'), //创建一个style元素
        head = document.head || document.getElementsByTagName('head')[0]; //获取head元素
      style.type = 'text/css'; //这里必须显示设置style元素的type属性为text/css,否则在ie中不起作用
      if (style.styleSheet) { //IE
        var func = function () {
          try { //防止IE中stylesheet数量超过限制而发生错误
            style.styleSheet.cssText = cssText;
          } catch (e) {

          }
        }
        //如果当前styleSheet还不能用,则放到异步中则行
        if (style.styleSheet.disabled) {
          setTimeout(func, 10);
        } else {
          func();
        }
      } else { //w3c
        //w3c浏览器中只要创建文本节点插入到style元素中就行了
        var textNode = document.createTextNode(cssText);
        style.appendChild(textNode);
      }
      head.appendChild(style); //把创建的style元素插入到head中
    }

    addCSS(
      'body{height:2000px;}.candy_div1{position:fixed;top:80%;right:0;width:30px;height:30px;border-radius:10px;background:rgba(0,0,0,0);}.candy_div2{position:relative;left:5px;width:0;height:0;border:10px solid transparent;border-bottom-color:rgba(0,0,0,0);}'
      );

})();