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
1. Business scenario introduction Suppose there i...
1. A static page means that there are only HTML ta...
one. Overview of IE8 Compatibility View <br /&...
<a href="http://" style="cursor...
1. The difference between Http and Https HTTP: It...
I personally feel that the development framework ...
Table of contents 1. Maven Dependency 2. Menu rel...
Table of contents Preface Static scope vs. dynami...
Preface Through my previous Tomcat series of arti...
Table of contents Basic Configuration Entry file ...
1. Add MySQL Yum repository MySQL official websit...
1. Check the character set of the database The ch...
What is a big deal? Transactions that run for a l...
Preface In WeChat applet development (native wxml...
1. Why do we need to divide tables and partitions...