- 首先获取图片大小
参考这里:https://www.jianshu.com/p/41ff1d103d3f - 代码示例:监听数据表格单元格,实现点击单元格弹出原始尺寸的图片
//监听单元格事件,点击认证按钮出现对应认证图片
table.on('tool(dataTable)', function (obj) {
if (obj.event === 'checkYishou') {
//整行数据
var data = obj.data;
var img = new Image();
//图片地址
img.src = data.yishou_path;
if (img.complete) {
var areaW = img.width;
var areaH = img.height;
showImg(areaW, areaH, data);
} else {
img.onload = function () {
var areaW = img.width;
var areaH = img.height;
showImg(areaW, areaH, data);
}
}
}
//显示认证图片
function showImg(w, h, data) {
var setting = {
type: 1,
title: false,
offset: 'auto',
area: [w, h],
closeBtn: 0,
skin: 'layui-layer-nobg', //没有背景色
shadeClose: true,
shade: 0.6, //遮罩透明度
content: '<img src="' + data.yishou_path + '" alt="一手认证">'
};
layer.open(setting);
}
});
网友评论