问题
I know it's simple to add images to a photoswipe list with jquery, but I can't figure out how to update the image list while browsing the gallery, i.e. without going back to the image list. An alternative (without jquery because it adds images directly to photoswipe instance) I found is to use the code below, but it seems that the only possibility to have the list updated while in the gallery is to go back to the first image (before going to the first image, everything is a mess). Is there any function to refresh the list while browsing the gallery?
for (i = 0; i < fileList.length; i++) { //add new image list
console.log(fileList[i]);
instance.cache.images.push(new Code.PhotoSwipe.Image.ImageClass(fileList[i], fileList[i].url, fileList[i].caption, ''));
};
回答1:
You can add images to PhotoSwipe even when gallery is currently open.
Here is an example from documentation (see chapter Adding slides dynamically) where pswp is your PhotoSwipe object (what new PhotoSwipe() returns).
pswp.items.push({
src: "path/to/image.jpg",
w:1200,
h:500
});
It works for me in PhotoSwipe v4.1.1
来源:https://stackoverflow.com/questions/15204346/photoswipe-adding-images-during-gallery-show