├── .gitignore ├── snapshot.png ├── example ├── README.md ├── index.html └── docsify-scroll-to-top.min.js ├── package.json ├── LICENSE ├── README.md ├── dist └── docsify-scroll-to-top.min.js └── src └── docsify-scroll-to-top.js /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | -------------------------------------------------------------------------------- /snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengxiangqi/docsify-scroll-to-top/HEAD/snapshot.png -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # DocsifyScrollToTop 2 | 3 | ### Chapter 01 4 | 5 | ### Chapter 02 6 | 7 | ### Chapter 03 8 | 9 | ### Chapter 04 10 | 11 | ### Chapter 05 12 | 13 | ### Chapter 06 14 | 15 | ### Chapter 07 16 | 17 | ### Chapter 08 18 | 19 | ### Chapter 09 20 | 21 | ### Chapter 10 22 | 23 | ### Chapter 11 24 | 25 | ### Chapter 12 26 | 27 | ### Chapter 13 28 | 29 | ### Chapter 14 30 | 31 | ### Chapter 15 32 | 33 | ### Chapter 16 34 | 35 | ### Chapter 17 36 | 37 | ### Chapter 18 38 | 39 | ### Chapter 19 40 | 41 | ### Chapter 20 42 | 43 | ### Chapter 21 44 | 45 | ### Chapter 22 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docsify-scroll-to-top", 3 | "version": "1.0.2", 4 | "description": "docsify scroll to top plugin", 5 | "main": "dist/docsify-scroll-to-top.min.js", 6 | "directories": { 7 | "example": "example" 8 | }, 9 | "scripts": { 10 | "build": "npx uglify-js src/docsify-scroll-to-top.js -o dist/docsify-scroll-to-top.min.js", 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/zhengxiangqi/docsify-scroll-to-top.git" 16 | }, 17 | "keywords": [ 18 | "docsify", 19 | "scroll", 20 | "to", 21 | "top", 22 | "plugin" 23 | ], 24 | "author": "zhengxiangqi", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/zhengxiangqi/docsify-scroll-to-top/issues" 28 | }, 29 | "homepage": "https://github.com/zhengxiangqi/docsify-scroll-to-top#readme" 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019-present () 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

DocsifyScrollToTop

3 |
基于Docsify的页面滚动回顶部的插件
4 |
5 | 效果图 6 |
7 | 8 | 9 | ### 特性 10 | - 🎉 支持自动显示隐藏,靠近顶部时则隐藏按钮 11 | - 🎉 支持平滑滚动,不依赖jquery等别的插件 12 | - 🎉 支持修改文本 13 | - 🎉 支持调整位置 14 | 15 | 16 | ### 使用 17 | 1. 在 index.html 中引入脚本 18 | ```html 19 | 20 | ``` 21 | 22 | 2. 配置插件(可选) 23 | ```js 24 | window.$docsify = { 25 | // ... 26 | scrollToTop: { 27 | auto: true, 28 | text: 'Top', 29 | right: 15, 30 | bottom: 15, 31 | offset: 500 32 | } 33 | }; 34 | ``` 35 | 36 | 37 | ### 配置项 38 | scrollToTop.auto 39 | * 默认: true 40 | * 类型: Boolean 41 | * 描述: 是否自动隐藏按钮 42 | 43 | scrollToTop.text 44 | * 默认: Top 45 | * 类型: String 46 | * 描述: 按钮文字 47 | 48 | scrollToTop.right 49 | * 默认: 15 50 | * 类型: Number 51 | * 描述: 按钮距离窗口右侧距离 52 | 53 | scrollToTop.bottom 54 | * 默认: 15 55 | * 类型: Number 56 | * 描述: 按钮距离窗口底部距离 57 | 58 | scrollToTop.offset 59 | * 默认: 500 60 | * 类型: Number 61 | * 描述: 页面滚动多少距离后显示按钮,当auto配置为true时才有效果 62 | 63 | 64 | ### 相关链接 65 | [Docsify](https://github.com/docsifyjs/docsify/) 66 | 67 | 68 | ### LICENSE 69 | MIT 70 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | DocsifyScrollToTop 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /dist/docsify-scroll-to-top.min.js: -------------------------------------------------------------------------------- 1 | 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("span.scroll-to-top");$scrollBtn.style.display=offset>=CONFIG.offset?"block":"none"};hook.mounted(function(){var scrollBtn=document.createElement("span");scrollBtn.className="scroll-to-top";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);scrollBtn.onclick=function(e){e.stopPropagation();var step=window.scrollY/15;var scroll=function(){window.scrollTo(0,window.scrollY-step);if(window.scrollY>0){setTimeout(scroll,15)}};scroll()}})};$docsify.plugins=[].concat(install,$docsify.plugins); -------------------------------------------------------------------------------- /example/docsify-scroll-to-top.min.js: -------------------------------------------------------------------------------- 1 | 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("span.scroll-to-top");$scrollBtn.style.display=offset>=CONFIG.offset?"block":"none"};hook.mounted(function(){var scrollBtn=document.createElement("span");scrollBtn.className="scroll-to-top";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);scrollBtn.onclick=function(e){e.stopPropagation();var step=window.scrollY/15;var scroll=function(){window.scrollTo(0,window.scrollY-step);if(window.scrollY>0){setTimeout(scroll,15)}};scroll()}})};$docsify.plugins=[].concat(install,$docsify.plugins); -------------------------------------------------------------------------------- /src/docsify-scroll-to-top.js: -------------------------------------------------------------------------------- 1 | var CONFIG = { 2 | auto: true, 3 | text: 'Top', 4 | right: 15, 5 | bottom: 15, 6 | offset: 500 7 | }; 8 | 9 | var install = function (hook, vm) { 10 | var opts = vm.config.scrollToTop || CONFIG; 11 | CONFIG.auto = opts.auto && typeof opts.auto === 'boolean' ? opts.auto : CONFIG.auto; 12 | CONFIG.text = opts.text && typeof opts.text === 'string' ? opts.text : CONFIG.text; 13 | CONFIG.right = opts.right && typeof opts.right === 'number' ? opts.right : CONFIG.right; 14 | CONFIG.bottom = opts.bottom && typeof opts.bottom === 'number' ? opts.bottom : CONFIG.bottom; 15 | CONFIG.offset = opts.offset && typeof opts.offset === 'number' ? opts.offset : CONFIG.offset; 16 | 17 | var onScroll = function(e) { 18 | if (!CONFIG.auto) { 19 | return; 20 | } 21 | var offset = window.document.documentElement.scrollTop; 22 | var $scrollBtn = Docsify.dom.find('span.scroll-to-top'); 23 | $scrollBtn.style.display = offset >= CONFIG.offset ? "block" : "none"; 24 | }; 25 | 26 | hook.mounted(function() { 27 | var scrollBtn = document.createElement('span'); 28 | scrollBtn.className = 'scroll-to-top'; 29 | scrollBtn.style.display = CONFIG.auto ? 'none' : 'block'; 30 | scrollBtn.style.overflow = 'hidden'; 31 | scrollBtn.style.position = 'fixed'; 32 | scrollBtn.style.right = CONFIG.right + 'px'; 33 | scrollBtn.style.bottom = CONFIG.bottom + 'px'; 34 | scrollBtn.style.width = '50px'; 35 | scrollBtn.style.height = '50px'; 36 | scrollBtn.style.background = 'white'; 37 | scrollBtn.style.color = '#666'; 38 | scrollBtn.style.border = '1px solid #ddd'; 39 | scrollBtn.style.borderRadius = '4px'; 40 | scrollBtn.style.lineHeight = '42px'; 41 | scrollBtn.style.fontSize = '16px'; 42 | scrollBtn.style.textAlign = 'center'; 43 | scrollBtn.style.boxShadow = '0px 0px 6px #eee'; 44 | scrollBtn.style.cursor = 'pointer'; 45 | var textNode = document.createTextNode(CONFIG.text); 46 | scrollBtn.appendChild(textNode); 47 | document.body.appendChild(scrollBtn); 48 | window.addEventListener('scroll', onScroll); 49 | scrollBtn.onclick = function (e) { 50 | e.stopPropagation(); 51 | var step = window.scrollY / 15; 52 | var scroll = function() { 53 | window.scrollTo(0, window.scrollY - step); 54 | if(window.scrollY > 0) { 55 | setTimeout(scroll, 15); 56 | } 57 | }; 58 | scroll(); 59 | }; 60 | }); 61 | }; 62 | 63 | $docsify.plugins = [].concat(install, $docsify.plugins); 64 | --------------------------------------------------------------------------------