双击图片弹出插件

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双击图片弹出插件</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }
        .image-container {
            display: inline-block;
            margin: 10px;
        }
        .image-container img {
            max-width: 300px;
            cursor: pointer;
            border: 2px solid #ddd;
            border-radius: 5px;
            transition: transform 0.3s;
        }
        .image-container img:hover {
            transform: scale(1.02);
        }
        .modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.8);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }
        .modal-content {
            max-width: 80%;
            max-height: 80%;
        }
        .modal-content img {
            max-width: 100%;
            max-height: 100%;
            border: 5px solid white;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
        }
        .close-btn {
            position: absolute;
            top: 20px;
            right: 30px;
            color: white;
            font-size: 30px;
            cursor: pointer;
        }
        .credit {
            position: fixed;
            bottom: 10px;
            right: 10px;
            color: #aaa;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <h1>双击图片查看大图</h1>
    <div class="image-container">
        <img src="https://picsum.photos/300/200" alt="示例图片1" class="zoomable">
    </div>
    <div class="image-container">
        <img src="https://picsum.photos/300/200" alt="示例图片2" class="zoomable">
    </div>
    <div class="image-container">
        <img src="https://picsum.photos/300/300" alt="示例图片3" class="zoomable">
    </div>

    <div class="modal-overlay" id="imageModal">
        <span class="close-btn">&times;</span>
        <div class="modal-content">
            <img id="modalImage" src="" alt="放大图片">
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            // 双击图片显示模态框
            $('.zoomable').dblclick(function() {
                var imgSrc = $(this).attr('src');
                $('#modalImage').attr('src', imgSrc);
                $('#imageModal').fadeIn();
            });

            // 点击关闭按钮或模态框背景关闭模态框
            $('.close-btn, #imageModal').click(function(e) {
                if (e.target !== this && !$(e.target).hasClass('close-btn')) return;
                $('#imageModal').fadeOut();
            });

            // 按ESC键关闭模态框
            $(document).keyup(function(e) {
                if (e.key === "Escape") {
                    $('#imageModal').fadeOut();
                }
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值