欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 鼠标过处创建烟雾

鼠标过处创建烟雾

2025/6/27 22:39:44 来源:https://blog.csdn.net/weixin_41334434/article/details/147638372  浏览:    关键词:鼠标过处创建烟雾

 

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>鼠标过处创建烟雾</title><style>* {margin: 0;padding: 0;box-sizing: border-box;}body {display: flex;justify-content: center;align-items: center;min-height: 100vh;background: #111;}.btn {position: relative;padding: 20px 40px;background: #3498db;color: #fff;text-transform: uppercase;border-radius: 5px;font-size: 3em;cursor: pointer;overflow: hidden;}.particle {position: absolute;width: 8px;height: 8px;border-radius: 50%;background-color: #fff;pointer-events: none;opacity: 1;animation: animate 1s ease-in-out forwards;}@keyframes animate {to {opacity: 0;transform: translate(var(--tx), var(--ty)) scale(5);}}}</style>
</head>
<body><button class="btn" id="btn">smoke</button><script>let btn = document.getElementById('btn');btn.addEventListener('mousemove', e => {let rect = btn.getBoundingClientRect();let x = e.clientX - rect.left;let y = e.clientY - rect.top;let particleCount = 20;for (let index = 0; index < particleCount; index++) {createParticle(x, y);}});function createParticle(x, y) {let particle = document.createElement('div');particle.classList.add('particle');particle.style.left = `${x}px`;particle.style.top = `${y}px`;let angel = Math.random() * 2 * Math.PI;let distance = Math.random() * 80 + 20;let tx = Math.cos(angel) * distance;let ty = Math.sin(angel) * distance;particle.style.setProperty('--tx', `${tx}px`);particle.style.setProperty('--ty', `${ty}px`);btn.appendChild(particle);setTimeout(() => {particle.remove();}, 1000);}</script>
</body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词