鼠标拖尾~~~

自用

  1. // ==UserScript==
  2. // @name 鼠标拖尾~~~
  3. // @license 弗莱克斯
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.0.1
  6. // @description 自用
  7. // @author You
  8. // @match *://*/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Your code here...
  17.  
  18. let canvas=document.createElement("canvas");
  19. canvas.setAttribute('id','canvas');
  20. let w=window.innerWidth
  21. let h=window.innerHeight
  22. canvas.style.cssText=`
  23. width: ${w}px;
  24. height: ${h}px;
  25. position:fixed;
  26. top:0;
  27. left:0;
  28. z-index:-10;
  29. `;
  30. document.body.appendChild(canvas);
  31. canvas.width = w;
  32. canvas.height = h;
  33. var ctx = canvas.getContext('2d');
  34. let arr = [];
  35. let flag = 0;
  36. let time;
  37.  
  38. //页面改变时样式
  39. window.onresize=function(){
  40. ctx.clearRect(0, 0, w, h)
  41. w=window.innerWidth
  42. h=window.innerHeight
  43. canvas.style.cssText=`
  44. width: ${w}px;
  45. height: ${h}px;
  46. position:fixed;
  47. top:0;
  48. left:0;
  49. z-index:-10;
  50. `;
  51. canvas.width = w;
  52. canvas.height = h;
  53. }
  54. //创建的粒子类
  55. class points {
  56. constructor(x, y) {
  57. this.x = Math.random() * 40 - 20 + x
  58. this.y = Math.random() * 40 - 20 + y
  59. this.r = Math.random() * 4 + 2
  60. this.opacity = 1
  61. this.color = randomColor()
  62. this.movex = Math.sin(Math.random() * 2 * Math.PI) * 0.3
  63. this.movey = Math.sin(Math.random() * 2 * Math.PI) * 0.3
  64. this.style = Math.floor(Math.random()*2)
  65. }
  66. disappear() {
  67. this.opacity -= 0.02
  68. this.opacity <= 0 ? this.opacity = 0 : 0
  69. this.x += this.movex
  70. this.y += this.movey
  71. }
  72.  
  73. draw() {
  74. this.disappear()
  75. switch (this.style) {
  76. case 0:
  77. this.rec()
  78. break;
  79. case 1:
  80. this.arc()
  81. break;
  82. }
  83.  
  84. }
  85. rec() {
  86. ctx.beginPath()
  87. ctx.fillStyle = `rgba(${this.color},${this.opacity})`
  88. ctx.fillRect(this.x, this.y, this.r, this.r)
  89. ctx.shadowColor = '#fff';
  90. ctx.shadowBlur = 3 * this.r;
  91. ctx.fill()
  92. }
  93. arc() {
  94. ctx.beginPath()
  95. ctx.fillStyle = `rgba(${this.color},${this.opacity})`
  96. ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2)
  97. ctx.shadowColor = '#fff';
  98. ctx.shadowBlur = 3 * this.r;
  99. ctx.fill()
  100. }
  101.  
  102. }
  103.  
  104. window.addEventListener("mousemove", (e) => {
  105. arr.push(new points(e.clientX, e.clientY))
  106. })
  107.  
  108. function randomColor() {
  109. let u = `${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)}`
  110. return u
  111. }
  112. //动画
  113. function animate() {
  114. ctx.clearRect(0, 0, w, h)
  115. arr.forEach((item, index) => {
  116. if (item.opacity == 0) {
  117. arr.splice(index, 1)
  118. }
  119. item.draw()
  120. })
  121. window.requestAnimationFrame(animate)
  122. }
  123. animate()
  124.  
  125. })();

QingJ © 2025

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