记录:图片点击放大
1,img 增加 data-image-show 属性
<img src="<%=spec_list[i].form.spec_image%>" style="max-width: 30px;" data-image-show>
2,将下面代码放在backend-init.js文件中
$('body').on('click', '[data-image-show]', function () {
var img = new Image();
var imgWidth = this.getAttribute('data-width') || '480px';
img.onload = function () {
var $content = $(img).appendTo('body').css({background: '#fff', width: imgWidth, height: 'auto'});
Layer.open({
type: 1, area: imgWidth, title: false, closeBtn: 1,
skin: 'layui-layer-nobg', shadeClose: true, content: $content,
end: function () {
$(img).remove();
},
success: function () {
}
});
};
img.onerror = function (e) {
};
img.src = this.getAttribute('data-image-show') || this.src;
});