点击弹出爱心

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击弹出爱心</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
            cursor: pointer;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        
        .heart {
            position: absolute;
            width: 20px;
            height: 20px;
            background-color: red;
            transform: rotate(45deg);
            pointer-events: none;
            animation: heartAnimation 1s ease-out;
        }
        
        .heart:before, .heart:after {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            background-color: red;
            border-radius: 50%;
        }
        
        .heart:before {
            top: -10px;
            left: 0;
        }
        
        .heart:after {
            top: 0;
            left: -10px;
        }
        
        @keyframes heartAnimation {
            0% {
                transform: rotate(45deg) scale(0.8);
                opacity: 1;
            }
            100% {
                transform: rotate(45deg) scale(1.5);
                opacity: 0;
            }
        }
        
        .footer {
            position: fixed;
            bottom: 10px;
            width: 100%;
            text-align: center;
            color: #888;
        }
        
        .footer a {
            color: #ff69b4;
            text-decoration: none;
        }
    </style>
</head>
<body>

    <script>
        document.addEventListener('click', function(e) {
            // 创建爱心元素
            const heart = document.createElement('div');
            heart.className = 'heart';
            
            // 设置爱心位置为点击位置
            heart.style.left = (e.clientX - 10) + 'px';
            heart.style.top = (e.clientY - 10) + 'px';
            
            // 随机颜色
            const colors = ['#ff0000', '#ff69b4', '#ff1493', '#ff00ff', '#ff6347'];
            const randomColor = colors[Math.floor(Math.random() * colors.length)];
            
            heart.style.backgroundColor = randomColor;
            heart.querySelectorAll(':before, :after').forEach(el => {
                el.style.backgroundColor = randomColor;
            });
            
            // 添加到页面
            document.body.appendChild(heart);
            
            // 动画结束后移除元素
            setTimeout(() => {
                heart.remove();
            }, 1000);
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值