zhengxiangqi / docsify-scroll-to-top Goto Github PK
View Code? Open in Web Editor NEW基于Docsify的页面滚动回顶部的插件
License: MIT License
基于Docsify的页面滚动回顶部的插件
License: MIT License
window.document.documentElement.scrollTop
在旧版 Edge 和 iOS 13 以下版本的 Safari 中不起效(iOS 13 可以),向下滚动时按钮不显示。
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.
添加以后,影响了左侧的滚动锚点计算
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.