<!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 {
overflow: hidden;
background: #000;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: Arial, sans-serif;
}
.container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.diamond {
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
background: rgba(255, 255, 255, 0.5);
transform: rotate(45deg);
box-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff;
animation: diamondAnimation 10s linear infinite;
opacity: 0;
}
@keyframes diamondAnimation {
0% {
transform: rotate(45deg) scale(0.1) translateX(0);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: rotate(405deg) scale(1) translateX(300px);
opacity: 0;
}
}
.content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
z-index: 100;
}
h1 {
font-size: 3rem;
margin-bottom: 20px;
text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #e60073;
}
p {
font-size: 1.2rem;
margin-bottom: 30px;
}
a {
color: #fff;
text-decoration: none;
font-size: 1.1rem;
padding: 10px 20px;
border: 1px solid #fff;
border-radius: 5px;
transition: all 0.3s ease;
}
a:hover {
background: rgba(255, 255, 255, 0.2);
box-shadow: 0 0 10px #fff, 0 0 20px #fff;
}
</style>
</head>
<body>
<div class="container" id="container"></div>
<div class="content">
<h1>钻石旋转特效</h1>
<p>这是一个炫酷的钻石旋转背景动画</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const container = document.getElementById('container');
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
function createDiamonds() {
const count = 50;
for (let i = 0; i < count; i++) {
const diamond = document.createElement('div');
diamond.classList.add('diamond');
// 随机大小
const size = Math.random() * 20 + 5;
diamond.style.width = `${size}px`;
diamond.style.height = `${size}px`;
// 随机颜色
const color = colors[Math.floor(Math.random() * colors.length)];
diamond.style.background = color;
diamond.style.boxShadow = `0 0 10px ${color}, 0 0 20px ${color}`;
// 随机位置
const angle = Math.random() * Math.PI * 2;
const distance = Math.random() * 100 + 50;
// 随机动画延迟和持续时间
const delay = Math.random() * 5;
const duration = Math.random() * 5 + 5;
diamond.style.animation = `diamondAnimation ${duration}s linear ${delay}s infinite`;
// 初始位置
diamond.style.left = `${Math.cos(angle) * distance}px`;
diamond.style.top = `${Math.sin(angle) * distance}px`;
container.appendChild(diamond);
}
}
createDiamonds();
});
</script>
</body>
</html>
钻石旋转背景动画特效
于 2025-05-27 15:04:17 首次发布
963

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



