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