5180
7
1
0
// ==UserScript==
// @name 到顶到底
// @version 1
// @run-at
// ==/UserScript==
function toTopLikeKuAn() {
var toTopBtn = document.createElement("div");
toTopBtn.id = "toTopBtn";
toTopBtn.setAttribute("style","font-size:4vw !important;width:37.5px !important;height:37.5px !important;line-height:37.5px !important;text-align:center !important;background:url(https://img1.baidu.com/it/u=995516280,1415356790&fm=253&fmt=auto&app=138&f=JPEG?w=260&h=368) no-repeat center center !important;background-size:11px 11px !important;background-color:rgba(250,250,250,0.9) !important;box-shadow:0px 1px 1px rgba(0,0,0,0.4);color:#000 !important;position:fixed !important;bottom:6vh !important;right:45vw !important;z-index:99 !important;border-radius:100% !important;display:none;");
document.body.appendChild(toTopBtn);
};
function isScrollToTop() {
var toTopTimer;
var theBody = document.getElementsByTagName('body')[0];
var topTopBtn = document.getElementById('toTopBtn');
document.ontouchstart = function (e) {
if (toTopTimer) {
clearTimeout(toTopTimer);
};
mystartY = e.changedTouches[0].clientY;
};
document.ontouchmove = function (e) {
myendY = e.changedTouches[0].clientY;
var myY = myendY - mystartY;
if (myY > 0){
toTopBtn.style.opacity = "1";
toTopBtn.style.display = "block";
toTopBtn.style.transform = "rotateZ(0deg)";
toTopBtn.style.boxShadow = "0px 1px 1px rgba(0,0,0,0.4)";
toTopBtn.onclick = function () {
window.scrollTo(0,0);
this.style.display = "none";
toTopBtn.removeEventListener('click',this,false);
};
} else if (myY < 0) {
toTopBtn.style.opacity = "1";
toTopBtn.style.display = "block";
toTopBtn.style.transform = "rotateZ(180deg)";
toTopBtn.style.boxShadow = "0px -1px 1px rgba(0,0,0,0.4)";
toTopBtn.onclick = function () {
window.scrollTo(0,99999);
this.style.display = "none";
toTopBtn.removeEventListener('click',this,false);
};
}else {
toTopBtn.style.display = "none";
};
};
document.ontouchend = function (e) {
toTopTimer = setTimeout(function () {
toTopBtn.style.transitionProperty="opacity,background-color";
toTopBtn.style.transitionDuration="300ms";
toTopBtn.style.transitionTimingFunction = "linear";
toTopBtn.style.opacity = "0";
toTopBtn.style.backgroundColor = "rgba(200,200,200,1)";
setTimeout(function() {
toTopBtn.style.display = "none";
toTopBtn.style.backgroundColor = "rgba(250,250,250,0.9)";
},500);
},3000);
};
};
var isHaveToTopBtn;
isHaveToTopBtn = document.getElementById('toTopBtn');
if (!isHaveToTopBtn) {
toTopLikeKuAn();
isScrollToTop();
};