回到顶部

返回顶部

  1. // ==UserScript==
  2. // @name 回到顶部
  3. // @namespace 回到顶部
  4. // @version 1
  5. // @description 返回顶部
  6. // @author 忆风
  7. // @date 2020-04-25
  8. // @modified 2021-08-23
  9. // @match *://*
  10. // @license BSD 3-Clause License
  11. // @grant unsafeWindow
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16.  
  17. const css = `
  18. #top {
  19. position: fixed;
  20. right: 110.75px;
  21. bottom: 50px;
  22. width: 150px;
  23. height: 174px;
  24. cursor: pointer;
  25. z-index: 998;
  26. background-position: 0 0;
  27. text-align: center;
  28. background-image: url(https://vkceyugu.cdn.bspapp.com/VKCEYUGU-1d54fa1d-9401-4557-9110-96deeab99096/0b59ae81-0662-40bf-b87b-04966990a3ab.png);
  29. background-repeat: no-repeat;
  30.  
  31. }
  32. #top:hover{
  33. background-image: url(https://vkceyugu.cdn.bspapp.com/VKCEYUGU-1d54fa1d-9401-4557-9110-96deeab99096/f0b56473-6683-422e-8b73-a0d5fa90b1dd.png);
  34. -webkit-animation: ani steps(1, start) 0.5s infinite;
  35. animation: ani steps(1, start) 0.5s infinite;
  36. }
  37. @keyframes ani{
  38. 0% {
  39. background-position: 0 0;
  40. }
  41.  
  42. 25% {
  43. background-position: -150px 0;
  44. }
  45. 50% {
  46. background-position: -300px 0;
  47. }
  48. 75% {
  49. background-position: -450px 0;
  50. }
  51. 100% {
  52. background-position: -600px 0;
  53. }
  54. }
  55. `;
  56. const sty = document.createElement('style');
  57. sty.innerHTML = css;
  58. sty.type = 'text/css';
  59. const head = document.querySelector('head');
  60. head.appendChild(sty);
  61. const body = document.querySelector("body");
  62. const div = document.createElement('div');
  63. div.id = "top";
  64. div.style = 'display:none;';
  65. div.addEventListener('click',function toTop(){
  66. console.log('1111');
  67. window.scrollTo({
  68. left: 0,
  69. top: 0,
  70. behavior: 'smooth'
  71. })
  72. })
  73. body.appendChild(div);
  74.  
  75. window.addEventListener("scroll",isdis)
  76. function isdis(){
  77. const top = this.document.querySelector('#top');
  78. let to = document.documentElement.scrollTop;
  79. let ischg = true;
  80. if(to>900 && ischg)
  81. {
  82. top.style.display = 'block';
  83. ischg = false;
  84. }
  85. else if(to<900){
  86. top.style.display = 'none';
  87. ischg = true;
  88. }
  89. }
  90.  
  91. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址