jq点击小图 弹出大图(更新版)

$(function(){
    $(".fj1-consult").on("click",function(){
        //设置弹框中图片的路径
        $(".layer_con img").attr("src","images/dx03.png");
        layer($(this));
    });
    function layer(small){
        $(".layer_con img").on("load",function(){
            var $con=$(".layer_con").height()+30;
            $(".layer_bg").css({"display":"block"});
            var $winH=$(window).height();
            if($con > $winH){
                $(".layer_con").css({"height":$winH,"display":"block","top":"0","margin-top":"0"});
            }else{
                $(".layer_con").css({"display":"block","top":"50%","margin-top":-$con/2});
            }
        })
    }
    $(".close").on("click",function(){
        $(this).parents(".layer_con").css("display","none");
        $(".layer_bg").css("display","none");
    });
}) 
<div class="layer_bg card-layerBg"></div>
<div class="layer_con card-layerCon">
    <div class="layer_main card-layerM">
        <img  src=""/>
    </div>
    <div class="close">x</div>
</div>
View Code
.card-layerBg {
    display: none;
    width: 100%;
    z-index: 999;
    position: fixed;
    background-color: #000;
    opacity: 0.5;
    top: 0;
    height: 100%;
    filter: alpha(opacity=50);
}

.card-layerCon {
    display: none;
    width: 600px;
    padding: 10px 30px 20px 0;
    background-color: #fff;
    z-index: 9999;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -300px;
    opacity: 1;
    filter: alpha(opacity=100);
    text-align:center;
}

.close {
    font-size: 33px;
    text-align: center;
    color: #ab2223;
    position: absolute;
    right: 10px;
    top: -8px;
    cursor: pointer;
}

.card-layerM {
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    padding-top: 25px;
    overflow-y: auto;
    max-height:100%;
    text-align: center;

}
.card-layerM img{
    width:auto;
    max-width:100%;
    max-height:100%;
}
View Code

 

转载于:https://www.cnblogs.com/dongxiaolei/p/6224907.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值