<!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;
background: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: Arial, sans-serif;
overflow: hidden;
}
.container {
position: relative;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.nail {
position: absolute;
width: 30px;
height: 100px;
background: linear-gradient(to bottom, #8B4513, #A0522D);
border-radius: 5px;
transform-origin: bottom center;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
animation: hammerHit 2s infinite;
}
.nail-head {
position: absolute;
top: -15px;
left: -5px;
width: 40px;
height: 20px;
background: linear-gradient(to bottom, #696969, #808080);
border-radius: 10px;
}
.hammer {
position: absolute;
width: 80px;
height: 200px;
background: linear-gradient(to right, #555, #333);
border-radius: 10px;
transform-origin: top center;
top: -100px;
left: 50%;
transform: translateX(-50%) rotate(-30deg);
animation: hammerSwing 2s infinite;
z-index: 10;
}
.hammer-head {
position: absolute;
bottom: 0;
left: -30px;
width: 140px;
height: 60px;
background: linear-gradient(to right, #333, #111);
border-radius: 10px;
}
.wood {
position: absolute;
bottom: 100px;
width: 300px;
height: 50px;
background: linear-gradient(to bottom, #8B4513, #A0522D);
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
@keyframes hammerSwing {
0%, 100% {
transform: translateX(-50%) rotate(-30deg);
}
50% {
transform: translateX(-50%) rotate(30deg);
}
}
@keyframes hammerHit {
0%, 100% {
transform: translateY(0) rotate(0deg);
}
50% {
transform: translateY(20px) rotate(5deg);
}
}
.link {
position: absolute;
bottom: 20px;
color: #333;
text-decoration: none;
font-size: 14px;
transition: all 0.3s;
}
.link:hover {
color: #0066cc;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<div class="wood"></div>
<div class="nail">
<div class="nail-head"></div>
</div>
<div class="hammer">
<div class="hammer-head"></div>
</div>
</div>
<script>
// 添加一些随机钉子
document.addEventListener('DOMContentLoaded', function() {
const container = document.querySelector('.container');
const wood = document.querySelector('.wood');
// 创建多个钉子
for (let i = 0; i < 5; i++) {
const nail = document.createElement('div');
nail.className = 'nail';
const nailHead = document.createElement('div');
nailHead.className = 'nail-head';
nail.appendChild(nailHead);
container.insertBefore(nail, wood);
// 随机位置
const leftPos = 100 + (i * 50);
nail.style.left = leftPos + 'px';
// 随机动画延迟
const delay = Math.random() * 2;
nail.style.animationDelay = delay + 's';
}
});
</script>
</body>
</html>
钉子动画特效
于 2025-06-04 14:09:59 首次发布