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://')) })