代码如下:
<!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>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #000;
overflow: hidden;
font-family: 'Arial Black', sans-serif;
}
.text-container {
position: relative;
text-align: center;
}
.shaking-text {
font-size: 5rem;
color: transparent;
background: linear-gradient(90deg, #ff00cc, #3333ff, #00ccff, #ff00cc);
background-size: 400% 100%;
-webkit-background-clip: text;
background-clip: text;
animation: shake 0.5s infinite alternate, gradient 8s linear infinite;
text-shadow: 0 0 10px rgba(255,255,255,0.3);
position: relative;
z-index: 2;
}
.shaking-text::before {
content: attr(data-text);
position: absolute;
left: 0;
top: 0;
color: rgba(255,255,255,0.2);
z-index: -1;
filter: blur(5px);
}
@keyframes shake {
0% {
transform: translateX(-5px) rotate(-2deg);
}
20% {
transform: translateX(5px) rotate(2deg);
}
40% {
transform: translateX(-5px) rotate(-2deg);
}
60% {
transform: translateX(5px) rotate(2deg);
}
80% {
transform: translateX(-5px) rotate(-2deg);
}
100% {
transform: translateX(5px) rotate(2deg);
}
}
@keyframes gradient {
0% {
background-position: 0% 50%;
}
100% {
background-position: 400% 50%;
}
}
.particles {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 1;
}
.particle {
position: absolute;
width: 3px;
height: 3px;
background: #fff;
border-radius: 50%;
opacity: 0;
animation: particle 3s infinite;
}
@keyframes particle {
0% {
transform: translate(0, 0);
opacity: 0;
}
20% {
opacity: 1;
}
100% {
transform: translate(var(--tx), var(--ty));
opacity: 0;
}
}
.footer {
position: fixed;
bottom: 30px;
color: rgba(255,255,255,0.5);
font-size: 14px;
text-align: center;
width: 100%;
}
.footer a {
color: rgba(255,255,255,0.7);
text-decoration: none;
transition: color 0.3s;
}
.footer a:hover {
color: #fff;
text-shadow: 0 0 10px #00ccff;
}
</style>
</head>
<body>
<div class="particles" id="particles"></div>
<div class="text-container">
<h1 class="shaking-text" data-text="炫酷抖动效果">炫酷抖动效果</h1>
</div>
<div class="footer">
</div>
<script>
// 创建粒子效果
const particlesContainer = document.getElementById('particles');
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
// 随机位置
const x = Math.random() * 100;
const y = Math.random() * 100;
// 随机移动距离
const tx = (Math.random() - 0.5) * 200;
const ty = (Math.random() - 0.5) * 200;
particle.style.left = `${x}%`;
particle.style.top = `${y}%`;
particle.style.setProperty('--tx', `${tx}px`);
particle.style.setProperty('--ty', `${ty}px`);
particle.style.animationDelay = `${Math.random() * 3}s`;
particlesContainer.appendChild(particle);
}
</script>
</body>
</html>