function showMedia(id, type, src) { var idBar = "#" + id; var width = $(idBar).width(); var height = $(idBar).height(); var scaleWH = width / height; var bigH = 500; var bigW = scaleWH * bigH; if (bigW > 900) { bigW = 900; bigH = bigW / scaleWH; } // 放大预览图片 layer.open({ type: 1, title: false, closeBtn: 1, shadeClose: true, area: [bigW + 'px', bigH + 'px'], //宽高 content: "<img width='" + bigW + "' height='" + bigH + "'controls=\"controls\" src=" + src + " />" }); } $('#idCardFront').bind('click', function () { var idBar = $("#idCardFront") var result = idBar[0].src; showMedia("idCardFront", "image", result); }); $('#idCardReverse').bind('click', function () { var idBar = $("#idCardReverse") var result = idBar[0].src; showMedia("idCardReverse", "image", result); }); $('#demo2 img').each(function(){ var _this = $(this); _this.on('click',function(e){ var idBar = _this var src = idBar[0].src; var width = $(idBar).width(); var height = $(idBar).height(); var scaleWH = width / height; var bigH = 500; var bigW = scaleWH * bigH; if (bigW > 900) { bigW = 900; bigH = bigW / scaleWH; } // 放大预览图片 layer.open({ type: 1, title: false, closeBtn: 1, shadeClose: true, area: [bigW + 'px', bigH + 'px'], //宽高 content: "<img width='" + bigW + "' height='" + bigH + "'controls=\"controls\" src=" + src + " />" }); }) })
layui图片点击放大
最新推荐文章于 2023-08-30 09:55:16 发布