Giter Club home page Giter Club logo

docsify-scroll-to-top's Introduction

Hi there 👋

ZhengXiangQi's GitHub Stats

docsify-scroll-to-top's People

Contributors

zhengxiangqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

docsify-scroll-to-top's Issues

Safari, Edge 下无法显示

window.document.documentElement.scrollTop 在旧版 Edge 和 iOS 13 以下版本的 Safari 中不起效(iOS 13 可以),向下滚动时按钮不显示。

Fixed script

Hello. First of all, i'm sorry for my bad english if there are some mistake.

I fixed the plugin and made another version. The problem was the element didn't work when i clicked it. I saw the code and made some modification and now it works.

Here it's the code:

var CONFIG = {
      auto: true,
      text: "Top",
      right: 15,
      bottom: 15,
      offset: 500
    };
    var install = function(hook, vm) {
      var opts = vm.config.scrollToTop || CONFIG;
      CONFIG.auto = opts.auto && typeof opts.auto === "boolean" ? opts.auto : CONFIG.auto;
      CONFIG.text = opts.text && typeof opts.text === "string" ? opts.text : CONFIG.text;
      CONFIG.right = opts.right && typeof opts.right === "number" ? opts.right : CONFIG.right;
      CONFIG.bottom = opts.bottom && typeof opts.bottom === "number" ? opts.bottom : CONFIG.bottom;
      CONFIG.offset = opts.offset && typeof opts.offset === "number" ? opts.offset : CONFIG.offset;


    var onScroll = function(e) {
        if (!CONFIG.auto) {
            return
        }
        var offset = window.document.documentElement.scrollTop;
        var $scrollBtn = Docsify.dom.find("button.scroll-to-top");
        $scrollBtn.style.display = offset >= CONFIG.offset ? "block" : "none";
    };

    function funclick() {

        var step = window.scrollY / 15;
        var scroll = function() {
            window.scrollTo(0, window.scrollY - step);
            if (window.scrollY > 0) {
                setTimeout(scroll, 15);
            }
        };
        scroll();
        
    };


    hook.mounted(function() {
        var scrollBtn = document.createElement("button");
        scrollBtn.className = "scroll-to-top";
        scrollBtn.id = "stt";
        scrollBtn.style.display = CONFIG.auto ? "none" : "block";
        scrollBtn.style.overflow = "hidden";
        scrollBtn.style.position = "fixed";
        scrollBtn.style.right = CONFIG.right + "px";
        scrollBtn.style.bottom = CONFIG.bottom + "px";
        scrollBtn.style.width = "50px";
        scrollBtn.style.height = "50px";
        scrollBtn.style.background = "white";
        scrollBtn.style.color = "#666";
        scrollBtn.style.border = "1px solid #ddd";
        scrollBtn.style.borderRadius = "4px";
        scrollBtn.style.lineHeight = "42px";
        scrollBtn.style.fontSize = "16px";
        scrollBtn.style.textAlign = "center";
        scrollBtn.style.boxShadow = "0px 0px 6px #eee";
        scrollBtn.style.cursor = "pointer";

        var textNode = document.createTextNode(CONFIG.text);
        scrollBtn.appendChild(textNode);
        document.body.appendChild(scrollBtn);
        window.addEventListener("scroll", onScroll);

    });

    hook.ready(function() {
        document.getElementById("stt").addEventListener("click", funclick);
        
    })
};
$docsify.plugins = [].concat(install, $docsify.plugins);

I'd like to see the update directly on the master branch but i don't know how to do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.