Skip to content

Instantly share code, notes, and snippets.

@ksk1015
Created September 27, 2016 14:18
Show Gist options
  • Save ksk1015/53a4a37efc1f71e827a2baac3cb052b2 to your computer and use it in GitHub Desktop.
Save ksk1015/53a4a37efc1f71e827a2baac3cb052b2 to your computer and use it in GitHub Desktop.
photoswipe initialize to set image size on load image
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