【jQuery】点击缩略图查看大图-imgbox

问题

点击缩略图,在当前页或在新标签中打开大图,这种体验不好。
能不能达到这样的效果:点击缩略图,在当前页弹出一个弹框,显示大图。

效果图

解决方案

通过使用jQuery插件imgbox来实现。

学习资源
  1. (jQuery Plugin - imgBox lightbox image)
    http://www.htmldrive.net/items/show/390/jQuery-Plugin-imgBox-lightbox-image.html

  2. (5种jQuery弹出大图效果)
    http://www.lanrentuku.com/js/tupian-933.html

解决具体步骤
引用资源: 
<link rel="stylesheet" href="imgbox/css/imgbox.css"/>
<script src="imgbox/js/jquery.min.js"></script>
<script src="imgbox/js/jquery.imgbox.pack.js"></script>
HTML代码
<a class="zoom-1" title="test my picture1" href="images/lou-normal.jpg">
    <img src="images/lou-min.jpg"/>
</a>
jQuery中代码
$("a.zoom-1").imgbox();
完整代码:
<html>
<head>
    <style>
        div{
            width:50%;
        }
    </style>
    <link rel="stylesheet" href="imgbox/css/imgbox.css"/>
    <script src="imgbox/js/jquery.min.js"></script>
    <script src="imgbox/js/jquery.imgbox.pack.js"></script>
    <script>
        $(document).ready(function(){
            $("a.zoom-1").imgbox();
            $("a.zoom-2").imgbox({'alignment':'center','zoomOpacity': true,'speedIn':0});
            $("a.zoom-3").imgbox({'overlayShow':true,'alignment':'center','speedIn':0,'speedOut':0});
            $("a.zoom-4").imgbox({'hideOnOverlayClick':true,'allowMultiple'    : false});
            $("a.zoom-5").imgbox({'hideOnContentClick':true,'allowMultiple'    : false});
            $("a.zoom-6").imgbox({'speedIn':0,'speedOut':0,'allowMultiple' : false});
        });
    </script>
</head>
<body>
<div>
    <a class="zoom-1" title="test my picture1" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
    <a class="zoom-2" title="test my picture2" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
    <a class="zoom-3" title="test my picture3" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
    <a class="zoom-4" title="test my picture4" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
    <a class="zoom-5" title="test my picture5" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
    <a class="zoom-6" title="test my picture6" href="images/lou-normal.jpg"><img src="images/lou-min.jpg"/></a>
</div>
</body>
</html>
小提示

更改效果可以通过:

  1. 更改源代码中的$.fn.imgbox.defaults
$.fn.imgbox.defaults = {
    padding: 10,
    alignment: 'auto', // auto OR center
    allowMultiple: true,
    autoScale: true,
    speedIn: 500,
    speedOut: 500,
    easingIn: 'swing',
    easingOut: 'swing',
    zoomOpacity: false,
    overlayShow: false,
    overlayOpacity: 0.5,
    hideOnOverlayClick: true,
    hideOnContentClick: true
};
  1. 给imgbox设置参数,
    例如:
$("a.zoom").imgbox({
    'zoomOpacity': true,
    'alignment': 'center'
});

其中参数列表如下:

资源下载(http://download.csdn.net/detail/ly1414725328/9095583

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值