JS:
<script>
document.addEventListener('mousemove', function(e) {
let body=document.querySelector("body")
let star=document.createElement("span")
star.style.left=e.offsetX+"px"
star.style.top=e.offsetY+"px"
body.appendChild(star)
setTimeout(()=>{
star.remove()
},1000)
})
</script>
CSS:
body {
background: #111;
/* 超出屏幕的不显示 */
overflow: hidden;
}
span {
position: absolute;
/* 禁用 */
pointer-events: none;
animation: fadeInOut 1s linear infinite;
}
@keyframes fadeInOut {
0%,
100% {
opacity: 1;
}
20%,
80% {
opacity: 1;
}
}
span:before {
content: '';
position: absolute;
width: 10px;
height: 10px;
background: url(../img/wu.png);
/* 让图片填满设置的框子大小 */
background-size: cover;
animation: moveShape 1s linear infinite;
}
@keyframes moveShape {
0% {
transform: translate(0) rotate(0deg);
}
100% {
transform: translate(100px) rotate(360deg)
}
}
效果图(图片可在css里自行更换):