js获取url的图片的长宽高 并用layer 打开
function openImg(url) {
var img = new Image(); //图片预加载
img.src=url;
// 判断是否有缓存
if(img.complete){
// 打印
// alert('from:complete : width:'+img.width+',height:'+img.height);
getImgWidthHeight(img,url);
}else{
// 加载完成执行
img.onload = function(){
// 打印
// alert('from:onload : width:'+img.width+',height:'+img.height);
getImgWidthHeight(img,url);
};
}
}
function getImgWidthHeight(img,url){
top.layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: [img.width + 'px', img.height + 'px'], //宽高
content: '<div><img src='+url+' /></div>'
});
}