This article shares with you a js special effect of spreading love when the mouse slides, the effect is as follows: The following is the code implementation, you are welcome to copy, paste and collect it. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Native JS to achieve mouse sliding love effect</title> <style> * { margin: 0; padding: 0; font-family: 'Microsoft YaHei', sans-serif; } body { height: 100vh; background: #000; overflow: hidden; } span { position: absolute; background: url(heart.png); pointer-events: none; width: 100px; height: 100px; background-size: cover; transform: translate(-50%, -50%); animation: animate 2s linear infinite; } @keyframes animate { 0% { transform: translate(-50%, -50%); opacity: 1; filter: hue-rotate(0deg); } 100% { transform: translate(-50%, -1000%); opacity: 0; filter: hue-rotate(360deg); } } </style> </head> <body> <script> document.addEventListener('mousemove', (e) => { let body = document.querySelector('body') let heart = document.createElement('span') let x = e.offsetX let y = e.offsetY heart.style.left = x + 'px' heart.style.top = y + 'px' let size = Math.random() * 100 heart.style.width = size + 'px' heart.style.height = size + 'px' body.appendChild(heart) setTimeout(() => { heart.remove() }, 3000) }) </script> </body> </html> The following is the picture heart.png introduced in the above code The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Docker uses Supervisor to manage process operations
>>: How to safely shut down MySQL
Current demand: There are two tables, group and f...
Whether you are a web designer or a UI designer, ...
As we all know, SSH is currently the most reliabl...
Table of contents BOM (Browser Object Model) 1. W...
Error message: user: 'root' host: `localh...
This article mainly introduces the implementation...
Preface When we were writing the horse, I guess e...
After spending half the night on it, I finally ma...
Preface Due to the needs of the company's bus...
Table of contents background Main content 1. Comp...
This article shares the specific code for JavaScr...
Table of contents The pitfalls Filling method Wha...
Recently, when I was drawing an interface, I enco...
Table of contents 1. Node builds HTTP server 2. H...
This article shares the specific code of using ca...