Layui layer.open pop-up layer picture (click Fangda in the list to view the picture)


------------------------------------toolbar
 <script type="text/html" id="imgDemo">
    <img src="{
   
   {d.goods_img}}" width="100%" onclick='previewImg(this)'>
  </script>

------------------------layui-table

<th lay-options="{field:'goods_img', width:90, toolbar: '#imgDemo'}"> 图片</th>

---------------------------js
<script>
    function previewImg(obj) {
      var img = new Image();
      img.src = obj.src;
      var height = img.height; //获取图片高度
      var width = img.width; //获取图片宽度
      if (height > 1000 || width > 800) {
        height = height / 1.5;
        width = width / 1.5;
      }
      var imgHtml = "<img src='" + obj.src + "' style='width: " + width + "px;height:" + height + "px'/>";
      layer.open({
        type: 1,
        offset: 'auto',
        area: [width + 'px', height + 'px'],
        shadeClose: true,//点击外围关闭弹窗
        scrollbar: true,//不现实滚动条
        title: false, //不显示标题
        content: imgHtml, //捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响
        cancel: function () {
  
        }
      });
    }
  </script>

Guess you like

Origin blog.csdn.net/PieroPc/article/details/134001524