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图片淡入淡出特效 - 99j.quest示例</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
        }
        .image-container {
            margin: 20px 0;
            height: 300px;
            position: relative;
        }
        .image-to-show {
            position: absolute;
            top: 0;
            left: 50%;
            transform: translateX(-50%);
            max-width: 100%;
            max-height: 300px;
            display: none;
        }
        button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 10px 5px;
            cursor: pointer;
            border-radius: 4px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        .footer {
            margin-top: 30px;
            color: #666;
            font-size: 14px;
        }
        .footer a {
            color: #4CAF50;
            text-decoration: none;
        }
        .footer a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>jQuery图片淡入淡出特效</h1>
        <p>点击按钮查看图片淡入淡出效果</p>
        
        <div class="image-container">
            <img src="https://picsum.photos/600/300?random=1" alt="示例图片1" class="image-to-show" id="image1">
            <img src="https://picsum.photos/600/300?random=2" alt="示例图片2" class="image-to-show" id="image2">
            <img src="https://picsum.photos/600/300?random=3" alt="示例图片3" class="image-to-show" id="image3">
        </div>
        
        <div class="button-group">
            <button id="showImage1">显示图片1</button>
            <button id="showImage2">显示图片2</button>
            <button id="showImage3">显示图片3</button>
        </div>
        
        <div class="footer">
            <p>特效示例代码来自 <a href="http://www.99j.quest" target="_blank">www.99j.quest</a></p>
        </div>
    </div>

    <script>
        $(document).ready(function() {
            // 默认显示第一张图片
            $('#image1').fadeIn(500);
            
            // 点击按钮切换图片
            $('#showImage1').click(function() {
                $('.image-to-show').fadeOut(500, function() {
                    $('#image1').fadeIn(500);
                });
            });
            
            $('#showImage2').click(function() {
                $('.image-to-show').fadeOut(500, function() {
                    $('#image2').fadeIn(500);
                });
            });
            
            $('#showImage3').click(function() {
                $('.image-to-show').fadeOut(500, function() {
                    $('#image3').fadeIn(500);
                });
            });
            
            // 控制台输出信息
            console.log('这个特效示例来自 http://www.99j.quest');
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值