jQuery五彩缤纷心形冒泡动画特效

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery五彩缤纷心形冒泡动画特效</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            overflow: hidden;
            background: #000;
            height: 100vh;
            cursor: pointer;
        }
        
        .heart {
            position: absolute;
            pointer-events: none;
            transform: translate(-50%, -50%);
            animation: float 4s ease-in-out infinite;
        }
        
        .heart:before, .heart:after {
            content: "";
            position: absolute;
            width: 100%;
            height: 100%;
            background: currentColor;
            border-radius: 50%;
        }
        
        .heart:before {
            left: -50%;
        }
        
        .heart:after {
            top: -50%;
        }
        
        @keyframes float {
            0% {
                transform: translate(-50%, -50%) scale(0.5);
                opacity: 1;
            }
            100% {
                transform: translate(-50%, -150%) scale(1);
                opacity: 0;
            }
        }
        
        .message {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-family: Arial, sans-serif;
            text-align: center;
            z-index: 100;
        }
        
        .message a {
            color: #ff69b4;
            text-decoration: none;
        }
        
        .message a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="message">
        <h1>五彩缤纷心形冒泡特效</h1>
        <p>点击屏幕任意位置创建心形泡泡</p>
    </div>

    <script>
        $(document).ready(function() {
            // 颜色数组
            const colors = [
                '#ff0000', '#ff69b4', '#ff1493', '#ff00ff', 
                '#9400d3', '#4b0082', '#0000ff', '#00bfff', 
                '#00ffff', '#00ff7f', '#7cfc00', '#ffff00', 
                '#ffa500', '#ff8c00', '#ff4500'
            ];
            
            // 点击事件
            $(document).on('click', function(e) {
                createHeart(e.pageX, e.pageY);
            });
            
            // 自动生成心形(可选)
            setInterval(function() {
                if (Math.random() > 0.7) {
                    const x = Math.random() * $(window).width();
                    const y = $(window).height() + 50;
                    createHeart(x, y);
                }
            }, 300);
            
            // 创建心形函数
            function createHeart(x, y) {
                const heart = $('<div class="heart"></div>');
                const size = Math.random() * 30 + 20;
                const color = colors[Math.floor(Math.random() * colors.length)];
                
                heart.css({
                    left: x,
                    top: y,
                    width: size + 'px',
                    height: size + 'px',
                    color: color,
                    animationDuration: (Math.random() * 3 + 2) + 's'
                });
                
                $('body').append(heart);
                
                // 动画结束后移除元素
                setTimeout(function() {
                    heart.remove();
                }, 4000);
            }
        });
    </script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值