layui表格图片点击放大功能

在这里插入图片描述
这里要加个图片样式,确保图片在表格中显示适合大小

<style type="text/css">
    .layui-table-cell{
      text-align:center;
      height: auto;
      white-space: normal;
    }
    .layui-table img{
      max-width:100px
    }
  </style>

放大效果
在这里插入图片描述
代码

表格显示图片并且添加点击事件

 cols: [[
        {title: '序号', field: 'index', align: 'center', type: 'numbers', width: 60},
        {title: '操作', field: 'right', align: 'center', toolbar: '#toolbar', width: 200},
        {title: '样品二维码', field: 'qr_filename', align: 'center', width: 130,
        templet: function dataUrl(d) {
           var img = "<img src=http://192.168.62.209:85/upload/image-qr/"+d.qr_filename+" οnclick=\"imgcli(this)\" >"; return img;
        }
        },
        {title: '样品编号', field: 'sampCode', align: 'center', width: 140},
        {title: '委托编号', field: 'oaId', align: 'center', width: 160},
        {title: '测试项目', field: 'taskName', align: 'center',width: 250},
        {title: '样品名称', field: 'sampName', align: 'center', width: 100},
        {title: '规格型号', field: 'sampType', align: 'center', width: 100},
        {title: '序列号', field: 'sampSn', align: 'center', width: 100},
        {title: '来样单位', field: 'prolineName', align: 'center', width: 200},
        {title: '来样日期 ', field: 'sampDate', align: 'center', width: 180},
      ]]

点击事件

<script>
  $('#divimg').click(function(){$(this).fadeOut(200)})
  function imgcli(obj){
    $('#divimg').fadeIn(200);
    $('#divimg img').attr('src',$(obj).attr("src"));
    $('#divimg img').css("margin-top","-"+$('#divimg img').height()/2+"px")
  }
</script>

点击放大图片后的位置大小

 <div  id="divimg" style="cursor:zoom-out;background: rgba(0,0,0,.6);width:100%;height:100%;position: absolute;z-index: 9999;left: 0;top: 0;display: none">
    <img style="width: 400px;left: 50%;top:50%;margin-left: -200px;position: absolute;">
  </div>
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值