<!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>鼠标特效</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #9df;
overflow: hidden;
height: 100vh;
}
span {
height: 10px;
width: 10px;
border-radius: 50%;
position: absolute;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 5px 5px 15px #45f, -5px -5px 15px #d80;
animation: box 3s linear forwards;
z-index: 3;
}
@keyframes box {
0% {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
filter: hue-rotate(0deg);
}
80% {
opacity: 1;
}
100% {
transform: translate(-50%, -1000%) scale(0.2);
opacity: 0;
filter: hue-rotate(720deg);
}
}
</style>
</head>
<body>
<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() * 5;
span.style.width = 10 + a + "px";
span.style.height = 10 + a + "px";
body.appendChild(span);
setTimeout(function() {
span.remove();
}, 3000);
});
</script>
</body>
</html>
index.html
index.html