fastadmin 框架中圖片點擊放大
fastadmin的原生圖片預覽,重新打開一個窗口太麻煩,使用layui做一個彈窗式的圖片預覽
1、將下面代碼放在backend-init.js文件中
$('body').on('click', '[data-tips-image]', 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-tips-image') || this.src; });
2、頁面的img標簽中添加 data-tips-image,點擊時自動彈出圖片預覽
<img src="{$goods.image}" data-tips-image alt="">
3、以下是預覽效果