返回顶部

下拉浏览长页的网页时,鼠标点击右下角的三角即可快速返回顶部

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         返回顶部
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  下拉浏览长页的网页时,鼠标点击右下角的三角即可快速返回顶部
// @author       kafukacc
// @match        https://hellogithub.com/
// @icon         none
// @grant        none
// @require  https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
// ==/UserScript==
$(function () {
        (function () {
            'use strict';
            $("body").append($("<a>△</a>"));
            $("a").addClass("to-top").css({
                "fontSize": "60px",
                "color": "rgba(238, 237, 237, 0.644)"
            }).on("mouseenter", function () {
                $(this).css("color", "gray");
            }).mouseleave(function () {
                $(this).css("color", "rgba(238, 237, 237, 0.644)");
            });

            $.fn.toTop = function (opt) {

                //variables
                var elem = this;
                var win = $(window);
                var doc = $('html, body');

                //Extended Options
                var options = $.extend({
                    autohide: true,
                    offset: 400,
                    speed: 500,
                    position: true,
                    right: 15,
                    bottom: 30
                }, opt);

                elem.css({
                    'cursor': 'pointer'
                });

                if (options.autohide) {
                    elem.css('display', 'none');
                }

                if (options.position) {
                    elem.css({
                        'position': 'fixed',
                        'right': options.right,
                        'bottom': options.bottom,
                    });
                }

                elem.click(function () {
                    doc.animate({
                        scrollTop: 0
                    }, options.speed);
                });

                win.scroll(function () {
                    var scrolling = win.scrollTop();

                    if (options.autohide) {
                        if (scrolling > options.offset) {
                            elem.fadeIn(options.speed);
                        } else elem.fadeOut(options.speed);
                    }

                });

            };

            $('.to-top').toTop();
        })();
    })