封装函数
/*弹出图片*/
function previewImg(url) {
var imgHtml = "
";
// 创建对象
var img = new Image();
img.src = url;
layer.open({
type: 1,
shade: 0.5,
area: [img.width + 'px', img.height + 'px'],
shadeClose: true,
scrollbar: false,
title: false, //显示标题
content: imgHtml, //捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响
cancel: function () {
//layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', { time: 5000, icon: 6 });
}
});
}
要点
// 创建对象
var img = new Image();
img.src = url;
area: [img.width + 'px', img.height + 'px'],
Done!