fastadmin 后台管理一些常用的前端功能模块汇总
在详情中点击图片放大
1
| <img src="https://dss3.baidu.com/-rVXeDTa2gU2pMbgoY3K/it/u=882494599,551867583&fm=202&mola=new&crop=v1" data-tips-image alt="" style="width: 120px;height: 120px">
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> $('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; }); </script>
|
注:在页面 img
标签中添加 data-tips-image
属性就能实现点击图片放大