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;
            padding: 0;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            overflow: hidden;
            font-family: Arial, sans-serif;
            cursor: none;
        }

        .face-container {
            position: relative;
            width: 400px;
            height: 400px;
        }

        .face {
            position: absolute;
            width: 300px;
            height: 350px;
            background: #FFD700;
            border-radius: 50%;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }

        .eye {
            position: absolute;
            width: 60px;
            height: 60px;
            background: white;
            border-radius: 50%;
            top: 100px;
            box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .eye.left {
            left: 80px;
        }

        .eye.right {
            right: 80px;
        }

        .pupil {
            position: absolute;
            width: 30px;
            height: 30px;
            background: #333;
            border-radius: 50%;
            top: 15px;
            left: 15px;
            transition: all 0.1s ease-out;
        }

        .eyebrow {
            position: absolute;
            width: 70px;
            height: 10px;
            background: #333;
            border-radius: 5px;
            top: 70px;
            transition: all 0.2s ease-out;
        }

        .eyebrow.left {
            left: 75px;
            transform: rotate(10deg);
        }

        .eyebrow.right {
            right: 75px;
            transform: rotate(-10deg);
        }

        .mouth {
            position: absolute;
            width: 120px;
            height: 40px;
            background: #FF6347;
            border-radius: 0 0 60px 60px;
            bottom: 80px;
            left: 50%;
            transform: translateX(-50%);
            transition: all 0.3s ease-out;
            overflow: hidden;
        }

        .tongue {
            position: absolute;
            width: 60px;
            height: 30px;
            background: #FF69B4;
            border-radius: 30px 30px 0 0;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            transition: all 0.3s ease-out;
        }

        .nose {
            position: absolute;
            width: 40px;
            height: 30px;
            background: #FFA500;
            border-radius: 50%;
            top: 170px;
            left: 50%;
            transform: translateX(-50%);
        }

        .blush {
            position: absolute;
            width: 50px;
            height: 20px;
            background: rgba(255, 105, 180, 0.3);
            border-radius: 50%;
            top: 180px;
            opacity: 0;
            transition: opacity 0.3s ease-out;
        }

        .blush.left {
            left: 60px;
        }

        .blush.right {
            right: 60px;
        }

        .cursor {
            position: absolute;
            width: 20px;
            height: 20px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 50%;
            pointer-events: none;
            transform: translate(-50%, -50%);
            z-index: 100;
            mix-blend-mode: difference;
        }

        .instructions {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            text-align: center;
            color: #666;
            font-size: 14px;
        }

        .website-link {
            position: absolute;
            bottom: 50px;
            left: 0;
            width: 100%;
            text-align: center;
            color: #666;
            font-size: 14px;
        }

        .website-link a {
            color: #4a6baf;
            text-decoration: none;
        }

        .website-link a:hover {
            text-decoration: underline;
        }

        /* 表情变化 */
        body:hover .eyebrow.left {
            transform: rotate(20deg);
        }

        body:hover .eyebrow.right {
            transform: rotate(-20deg);
        }

        body:hover .mouth {
            height: 60px;
            border-radius: 0 0 80px 80px;
        }

        body:hover .tongue {
            height: 40px;
        }

        body:hover .blush {
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="face-container">
        <div class="face">
            <div class="eyebrow left"></div>
            <div class="eyebrow right"></div>
            <div class="eye left">
                <div class="pupil" id="left-pupil"></div>
            </div>
            <div class="eye right">
                <div class="pupil" id="right-pupil"></div>
            </div>
            <div class="nose"></div>
            <div class="mouth">
                <div class="tongue"></div>
            </div>
            <div class="blush left"></div>
            <div class="blush right"></div>
        </div>
    </div>

    <div class="cursor" id="cursor"></div>
    

    
    <div class="instructions">
        移动鼠标控制眼睛,悬停脸部查看表情变化
    </div>

    <script>
        // 自定义光标和眼球跟随
        document.addEventListener('mousemove', function(e) {
            // 更新自定义光标位置
            const cursor = document.getElementById('cursor');
            cursor.style.left = e.clientX + 'px';
            cursor.style.top = e.clientY + 'px';
            
            // 获取脸部中心坐标
            const face = document.querySelector('.face');
            const faceRect = face.getBoundingClientRect();
            const faceCenterX = faceRect.left + faceRect.width / 2;
            const faceCenterY = faceRect.top + faceRect.height / 2;
            
            // 计算鼠标相对于脸部中心的位置
            const mouseX = e.clientX;
            const mouseY = e.clientY;
            const angleX = (mouseX - faceCenterX) / 30;
            const angleY = (mouseY - faceCenterY) / 30;
            
            // 限制眼球移动范围
            const limit = 10;
            const moveX = Math.max(-limit, Math.min(limit, angleX));
            const moveY = Math.max(-limit, Math.min(limit, angleY));
            
            // 更新眼球位置
            document.getElementById('left-pupil').style.transform = `translate(${moveX}px, ${moveY}px)`;
            document.getElementById('right-pupil').style.transform = `translate(${moveX}px, ${moveY}px)`;
        });
        
        // 点击时改变表情
        document.addEventListener('mousedown', function() {
            const mouth = document.querySelector('.mouth');
            const tongue = document.querySelector('.tongue');
            const eyebrows = document.querySelectorAll('.eyebrow');
            
            mouth.style.height = '30px';
            mouth.style.borderRadius = '30px 30px 60px 60px';
            tongue.style.height = '20px';
            
            eyebrows.forEach(brow => {
                brow.style.transform = 'translateY(10px)';
            });
        });
        
        document.addEventListener('mouseup', function() {
            const mouth = document.querySelector('.mouth');
            const tongue = document.querySelector('.tongue');
            const eyebrows = document.querySelectorAll('.eyebrow');
            
            mouth.style.height = '40px';
            mouth.style.borderRadius = '0 0 60px 60px';
            tongue.style.height = '30px';
            
            eyebrows.forEach(brow => {
                brow.style.transform = '';
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值