function openLayer(imgUrl) {
  var imgUrl = imgUrl;
  getImageWidth(imgUrl, function(w, h){
    w = h > 860? w/h*860: w
    h = h > 860? 860: h
    parent.layer.open({
        type: 1,
        title: false,
        offset: 'auto',
        area: [ w+'px', h+'px' ],
        shadeClose: true,
        content: '<div><img style="max-width: 100%;max-height: 100%" src="'+imgUrl+'"></div>'
    });
  });
}

// 获取图片真实高度
function getImageWidth(url, callback) {
  var img = new Image();
  img.src = url;
  // 如果图片被缓存,则直接返回缓存数据
  if (img.complete) {
    callback(img.width, img.height);
  } else {
    img.onload = function () {
      callback(img.width, img.height);
    }
  }
}

$('.pics-container').on('click', '.photo-item img', function() {
  openLayer(this.src.replace('http://', 'https://'))
})

前端box
75 声望1 粉丝