钉子动画特效

<!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;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        
        .container {
            position: relative;
            width: 300px;
            height: 400px;
            perspective: 1000px;
        }
        
        .nail {
            position: absolute;
            width: 30px;
            height: 100px;
            background: linear-gradient(to bottom, #8B4513, #A0522D);
            border-radius: 5px;
            top: 50px;
            left: 135px;
            transform-origin: center bottom;
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            animation: swing 2s infinite alternate ease-in-out;
        }
        
        .nail-head {
            position: absolute;
            width: 50px;
            height: 20px;
            background: linear-gradient(to bottom, #696969, #808080);
            border-radius: 10px;
            top: -10px;
            left: -10px;
        }
        
        .shadow {
            position: absolute;
            width: 60px;
            height: 20px;
            background: rgba(0,0,0,0.2);
            border-radius: 50%;
            bottom: 30px;
            left: 120px;
            filter: blur(5px);
            animation: shadow 2s infinite alternate ease-in-out;
        }
        
        .info {
            position: absolute;
            bottom: 20px;
            width: 100%;
            text-align: center;
            color: #666;
            font-size: 12px;
        }
        
        @keyframes swing {
            0% {
                transform: rotateZ(-15deg);
            }
            100% {
                transform: rotateZ(15deg);
            }
        }
        
        @keyframes shadow {
            0% {
                transform: scale(0.8) translateX(-10px);
                opacity: 0.6;
            }
            100% {
                transform: scale(1) translateX(10px);
                opacity: 0.8;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="nail">
            <div class="nail-head"></div>
        </div>
        <div class="shadow"></div>
        <div class="info">
        </div>
    </div>
    
    <script>
        // 添加鼠标交互效果
        document.addEventListener('mousemove', function(e) {
            const nail = document.querySelector('.nail');
            const shadow = document.querySelector('.shadow');
            
            // 计算鼠标位置与钉子中心的相对位置
            const containerRect = document.querySelector('.container').getBoundingClientRect();
            const centerX = containerRect.left + containerRect.width / 2;
            const centerY = containerRect.top + containerRect.height / 2;
            
            // 根据鼠标位置调整钉子倾斜角度
            const angle = (e.clientX - centerX) / 20;
            nail.style.transform = `rotateZ(${angle}deg)`;
            
            // 调整阴影
            const shadowScale = 1 - Math.abs(angle) / 100;
            const shadowOffset = angle * 0.8;
            shadow.style.transform = `scale(${shadowScale}) translateX(${shadowOffset}px)`;
        });
    </script>
</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值