文章目录

layer 图片自适应div

由 xiao 发布
        function other_preview(res){
            $("#preview_video").attr('src',res.other_card)
            var img = new Image();
            img.src = res.other_card;
            if (img.complete){
                var areaW = img.width;
                var areaH = img.height;
                showImg(areaW,areaH,res);
            }else{
                img.onload = function () {
                    var areaW = img.width;
                    var areaH = img.height;
                    showImg(areaW, areaH, res.other_card);
                }
            }
        }

function showImg(w,h,url){
    if (w > 4000 && w < 5000){
        w = w/5;
        h = h/5;
    }else if(w > 3000 && w < 4000){
        w = w/4;
        h = h/4;
    }else if(w > 2000 && w < 3000){
        w = w/3;
        h = h/3;
    }else if(w > 1000 && w < 2000){
        w = w/2;
        h = h/2;
    }
    $(".preview_content").css({width:w,height:h});
    $(".preview_img").css({width:w,height:h})
    var setting = {
        type: 1,
        title: false,
        area: [w, h],
        closeBtn: 0,
        shadeClose: true,
        shade: 0.1, //遮罩透明度
        content:$("#preview")
    };
    layer.open(setting);
}


暂无评论

发表评论