CSS鼠标特效【动画跟随】

2023-11-02

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里自行更换):

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS鼠标特效【动画跟随】 的相关文章

随机推荐