4411 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();
};
最新回复 (7)
  • 0 引用
    不赖,用了可以,出现一个小东西,很不赖
    2022-5-24 取消查看 收起回复
    花小梁: 谢谢,是基于谷花泰大佬的基础上改的,他的代码在M浏览器上用有点小问题
    2022-5-24回复
    花小梁: 更新了一下,修复了横屏模式下图标过大的问题
    2022-5-26回复
    d112233: 收到
    2022-5-28回复
    • 轻创社区 - 有源软件体验中心
      9
        登录 注册
返回