Mouse effects require the use of setTimeout to generate nodes at fixed times, delete nodes, and assign random widths, heights, and colors to the generated nodes, so that each effect node looks different. Note: The generated node needs to be absolutely positioned so that it is out of the document flow and does not affect the position of other elements on the page. Code example: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Mouse Effects</title> <style> * { margin: 0; padding: 0; } body { background-color: #9df; overflow: hidden; height: 100vh; } span { height: 30px; width: 30px; border-radius: 50%; position: absolute; pointer-events: none; transform: translate(-50%, -50%); box-shadow: 10px 10px 30px #45f, -10px -10px 30px #d80; animation: box 5s linear infinite; z-index: 3; } @keyframes box { 0% { transform: translate(-50%, -50%); opacity: 1; filter: hue-rotate(0deg); } 100% { transform: translate(-50%, -1000%); opacity: 1; filter: hue-rotate(720deg); } } </style> </head> <body> </body> </html> <script> document.addEventListener("mousemove", function(e) { var body = document.querySelector("body"); var span = document.createElement("span"); var x = e.offsetX var y = e.offsetY span.style.left = x + "px" span.style.top = y + "px"; console.log(x + ">>>" + y) var a = Math.random() * 30; span.style.width = 30 + a + "px"; span.style.height = 30 + a + "px"; body.appendChild(span); setTimeout(function() { span.remove(); // console.log("ok") }, 4500) }) </script> Running results: 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:
|
<<: Analysis of Linux Zabbix custom monitoring and alarm implementation process
>>: How to solve the mysql insert garbled problem
Table of contents JavaScript prototype chain Obje...
Screen Introduction Screen is a free software dev...
The system environment is server2012 1. Download ...
Table of contents Initialization of echart app-ba...
Export: docker save -o centos.tar centos:latest #...
This is a collection of commonly used but easily ...
Let’s learn together 1. Traditional methods Copy ...
When the created tab label exceeds the visible ar...
I always thought that Docker had no IP address. I...
Today I was browsing the blog site - shoptalkshow...
Introduction to border properties border property...
In the process of web front-end development, UI d...
1. Avoid declaring the page as XML type . The pag...
Pixel Resolution What we usually call monitor res...
Table of contents 1. Keywords 2. Deconstruction 3...