Created
September 27, 2016 14:18
-
-
Save ksk1015/53a4a37efc1f71e827a2baac3cb052b2 to your computer and use it in GitHub Desktop.
photoswipe initialize to set image size on load image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyPhotoswipeInit(pswpElement, PhotoSwipeUI_Default, items, options){ | |
var pswp = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options); | |
pswp.listen('imageLoadComplete', function(index, item) { | |
if ( item._myLoaded ) { | |
return; | |
} | |
var img = document.createElement('img'); | |
img.onload = function(){ | |
item.w = this.naturalWidth; | |
item.h = this.naturalHeight; | |
item._myLoaded = true; | |
pswp.updateSize(true); | |
}; | |
img.src = item.src; | |
}); | |
pswp.init(); | |
return pswp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment