back to top

回到顶部

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

QingJ © 2025

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