jQuery 3D图片翻牌切换

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery 3D图片翻牌切换</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            background: linear-gradient(135deg, #1e3c72, #2a5298);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            font-family: 'Arial', sans-serif;
            perspective: 1000px;
        }
        
        .container {
            width: 100%;
            max-width: 1200px;
            padding: 20px;
            text-align: center;
        }
        
        h1 {
            color: white;
            margin-bottom: 40px;
            text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
        }
        
        .card-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 30px;
        }
        
        .flip-card {
            width: 250px;
            height: 350px;
            position: relative;
            transform-style: preserve-3d;
            transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            cursor: pointer;
            margin-bottom: 20px;
        }
        
        .flip-card.flipped {
            transform: rotateY(180deg);
        }
        
        .flip-card-front, .flip-card-back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
        }
        
        .flip-card-front {
            background: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            transform: rotateY(0deg);
        }
        
        .flip-card-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: all 0.5s;
        }
        
        .flip-card-back {
            background: linear-gradient(45deg, #ff416c, #ff4b2b);
            color: white;
            padding: 20px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            transform: rotateY(180deg);
        }
        
        .card-title {
            font-size: 22px;
            margin-bottom: 15px;
        }
        
        .card-desc {
            font-size: 14px;
            line-height: 1.6;
            margin-bottom: 20px;
        }
        
        .card-btn {
            padding: 8px 20px;
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid white;
            color: white;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .card-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-3px);
        }
        
        .controls {
            margin-top: 40px;
            display: flex;
            justify-content: center;
            gap: 15px;
        }
        
        .control-btn {
            padding: 10px 25px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid white;
            color: white;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .control-btn:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        
        .footer {
            position: fixed;
            bottom: 20px;
            width: 100%;
            text-align: center;
            color: white;
        }
        
        .footer a {
            color: #4facfe;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .footer a:hover {
            color: #00f2fe;
            text-decoration: underline;
        }
        
        @media (max-width: 768px) {
            .flip-card {
                width: 200px;
                height: 300px;
            }
            
            .card-title {
                font-size: 18px;
            }
            
            .card-desc {
                font-size: 12px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>3D图片翻牌切换效果</h1>
        
        <div class="card-container" id="cardContainer">
            <!-- 卡片将通过jQuery动态添加 -->
        </div>
        
        <div class="controls">
            <button class="control-btn" id="flipAllBtn">翻转所有卡片</button>
            <button class="control-btn" id="resetAllBtn">重置所有卡片</button>
        </div>
    </div>
    
    <div class="footer">
        <p>jQuery 3D图片翻牌效果 © 2023</p>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            // 图片数据
            const cardData = [
                {
                    frontImg: "https://source.unsplash.com/random/500x750?nature",
                    title: "自然风光",
                    desc: "探索世界上最美丽的自然景观,感受大自然的鬼斧神工。",
                    bgColor: "linear-gradient(45deg, #4facfe, #00f2fe)"
                },
                {
                    frontImg: "https://source.unsplash.com/random/500x750?city",
                    title: "城市建筑",
                    desc: "现代都市的壮丽建筑,人类智慧与艺术的完美结合。",
                    bgColor: "linear-gradient(45deg, #ff758c, #ff7eb3)"
                },
                {
                    frontImg: "https://source.unsplash.com/random/500x750?animal",
                    title: "野生动物",
                    desc: "与地球上的其他居民相遇,了解它们的生存智慧。",
                    bgColor: "linear-gradient(45deg, #a18cd1, #fbc2eb)"
                },
                {
                    frontImg: "https://source.unsplash.com/random/500x750?technology",
                    title: "科技创新",
                    desc: "前沿科技改变世界,探索人类未来的无限可能。",
                    bgColor: "linear-gradient(45deg, #ff9a9e, #fad0c4)"
                }
            ];
            
            // 创建卡片
            function createCards() {
                const $cardContainer = $('#cardContainer');
                $cardContainer.empty();
                
                cardData.forEach((data, index) => {
                    const $card = $(`
                        <div class="flip-card" data-index="${index}">
                            <div class="flip-card-front">
                                <img src="${data.frontImg}" alt="${data.title}" class="flip-card-img">
                            </div>
                            <div class="flip-card-back" style="background: ${data.bgColor}">
                                <h3 class="card-title">${data.title}</h3>
                                <p class="card-desc">${data.desc}</p>
                                <button class="card-btn">查看详情</button>
                            </div>
                        </div>
                    `);
                    
                    // 添加点击事件
                    $card.on('click', function() {
                        $(this).toggleClass('flipped');
                    });
                    
                    $cardContainer.append($card);
                });
            }
            
            // 初始化卡片
            createCards();
            
            // 翻转所有卡片
            $('#flipAllBtn').on('click', function() {
                $('.flip-card').addClass('flipped');
            });
            
            // 重置所有卡片
            $('#resetAllBtn').on('click', function() {
                $('.flip-card').removeClass('flipped');
            });
            
            // 预加载图片
            function preloadImages() {
                cardData.forEach(data => {
                    const img = new Image();
                    img.src = data.frontImg;
                });
            }
            
            preloadImages();
            
            // 随机翻转一些卡片
            setTimeout(() => {
                $('.flip-card').each(function() {
                    if (Math.random() > 0.5) {
                        $(this).addClass('flipped');
                    }
                });
            }, 1000);
        });
    </script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值