CSS3人物头像鼠标跟随动画

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS3人物头像鼠标跟随动画</title>
    <style>
        body {
            margin: 0;
            height: 100vh;
            overflow: hidden;
            background: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: Arial, sans-serif;
            cursor: none;
        }
        
        .avatar-container {
            position: relative;
            width: 300px;
            height: 300px;
        }
        
        .avatar {
            position: absolute;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
            transition: transform 0.1s ease-out;
            transform-origin: center center;
        }
        
        .avatar:nth-child(1) {
            z-index: 5;
            filter: brightness(1.1);
        }
        
        .avatar:nth-child(2) {
            z-index: 4;
            filter: brightness(0.9) blur(1px);
            transition-delay: 0.05s;
        }
        
        .avatar:nth-child(3) {
            z-index: 3;
            filter: brightness(0.8) blur(2px);
            transition-delay: 0.1s;
        }
        
        .avatar:nth-child(4) {
            z-index: 2;
            filter: brightness(0.7) blur(3px);
            transition-delay: 0.15s;
        }
        
        .avatar:nth-child(5) {
            z-index: 1;
            filter: brightness(0.6) blur(4px);
            transition-delay: 0.2s;
        }
        
        .info {
            position: absolute;
            bottom: -50px;
            left: 0;
            width: 100%;
            text-align: center;
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="avatar-container">
        <div class="avatar"></div>
        <div class="avatar"></div>
        <div class="avatar"></div>
        <div class="avatar"></div>
        <div class="avatar"></div>
        <div class="info">鼠标移动查看跟随效果</div>
    </div>

    <script>
        document.addEventListener('mousemove', function(e) {
            const avatars = document.querySelectorAll('.avatar');
            const container = document.querySelector('.avatar-container');
            const rect = container.getBoundingClientRect();
            const centerX = rect.left + rect.width / 2;
            const centerY = rect.top + rect.height / 2;
            
            const mouseX = e.clientX;
            const mouseY = e.clientY;
            
            const angle = Math.atan2(mouseY - centerY, mouseX - centerX);
            const distance = Math.min(
                Math.sqrt(Math.pow(mouseX - centerX, 2) + Math.pow(mouseY - centerY, 2)) * 0.3, 
                50
            );
            
            avatars.forEach((avatar, index) => {
                const offset = (index + 1) * 5;
                const x = Math.cos(angle) * (distance + offset);
                const y = Math.sin(angle) * (distance + offset);
                const scale = 1 - index * 0.1;
                
                avatar.style.transform = `translate(${x}px, ${y}px) scale(${scale})`;
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值