<!DOCTYPE html>
<html lang="zh-CN">
<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 {
background: #121212;
min-height: 100vh;
overflow: hidden;
font-family: 'Arial', sans-serif;
cursor: none;
}
.container {
position: relative;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 10;
color: white;
text-align: center;
padding: 20px;
}
h1 {
font-size: 3rem;
margin-bottom: 20px;
background: linear-gradient(90deg, #ff8a00, #e52e71, #00b4db);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 0 10px rgba(255,255,255,0.2);
}
p {
font-size: 1.2rem;
margin-bottom: 30px;
max-width: 600px;
line-height: 1.6;
color: rgba(255,255,255,0.8);
}
.link-btn {
display: inline-block;
padding: 12px 30px;
background: linear-gradient(45deg, #00b4db, #0083b0);
color: white;
text-decoration: none;
border-radius: 50px;
font-weight: bold;
font-size: 1.1rem;
transition: all 0.3s ease;
box-shadow: 0 5px 15px rgba(0,180,219,0.4);
margin-top: 20px;
}
.link-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(0,180,219,0.6);
}
.footer {
position: fixed;
bottom: 20px;
width: 100%;
text-align: center;
color: rgba(255,255,255,0.5);
font-size: 0.9rem;
z-index: 10;
}
.footer a {
color: rgba(255,255,255,0.8);
text-decoration: none;
}
.footer a:hover {
color: white;
text-decoration: underline;
}
/* 粒子样式 */
.particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
transform: translate(-50%, -50%);
mix-blend-mode: screen;
transition: transform 0.1s ease-out;
}
/* 背景装饰粒子 */
.bg-particle {
position: absolute;
border-radius: 50%;
background: rgba(255,255,255,0.05);
animation: float 15s infinite linear;
}
@keyframes float {
0% {
transform: translateY(0) rotate(0deg);
}
100% {
transform: translateY(-100vh) rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<h1>鼠标粒子拖尾特效</h1>
<p>移动鼠标查看彩色粒子跟随效果。每个粒子都有独特的颜色和大小,形成流畅的拖尾动画。</p>
</div>
<div class="footer">
</div>
<script>
// 粒子系统
class ParticleSystem {
constructor() {
this.particles = [];
this.particleCount = 30; // 拖尾粒子数量
this.mouseX = window.innerWidth / 2;
this.mouseY = window.innerHeight / 2;
this.init();
}
init() {
// 创建背景粒子
this.createBackgroundParticles();
// 创建拖尾粒子
for (let i = 0; i < this.particleCount; i++) {
this.createParticle(i);
}
// 监听鼠标移动
document.addEventListener('mousemove', (e) => {
this.mouseX = e.clientX;
this.mouseY = e.clientY;
});
// 开始动画
this.animate();
}
createBackgroundParticles() {
const particleCount = 30;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('bg-particle');
// 随机大小
const size = Math.random() * 10 + 5;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机位置
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100 + 100}%`;
// 随机动画
particle.style.animationDuration = `${Math.random() * 10 + 10}s`;
particle.style.animationDelay = `${Math.random() * 5}s`;
document.body.appendChild(particle);
}
}
createParticle(index) {
const particle = document.createElement('div');
particle.classList.add('particle');
document.body.appendChild(particle);
this.particles.push({
element: particle,
x: this.mouseX,
y: this.mouseY,
size: Math.random() * 15 + 5,
color: this.getRandomColor(),
delay: index * 0.03,
speed: Math.random() * 0.2 + 0.05
});
}
getRandomColor() {
const hue = Math.floor(Math.random() * 360);
return `hsl(${hue}, 100%, 70%)`;
}
animate() {
this.particles.forEach((particle, index) => {
// 计算延迟因子
const delayFactor = 1 - (particle.delay * 2);
// 计算目标位置
const targetX = this.mouseX;
const targetY = this.mouseY;
// 更新粒子位置(带有延迟效果)
particle.x += (targetX - particle.x) * particle.speed * delayFactor;
particle.y += (targetY - particle.y) * particle.speed * delayFactor;
// 更新粒子样式
particle.element.style.left = `${particle.x}px`;
particle.element.style.top = `${particle.y}px`;
particle.element.style.width = `${particle.size * delayFactor}px`;
particle.element.style.height = `${particle.size * delayFactor}px`;
particle.element.style.backgroundColor = particle.color;
particle.element.style.opacity = delayFactor * 0.8;
particle.element.style.filter = `blur(${2 * (1 - delayFactor)}px)`;
});
requestAnimationFrame(() => this.animate());
}
}
// 初始化粒子系统
window.addEventListener('load', () => {
new ParticleSystem();
});
</script>
</body>
</html>
382

被折叠的 条评论
为什么被折叠?



