Open eshmh opened 1 month ago
I figured out one way to do it.
constructor(pswp, options) {
this.options = {
...defaultOptions,
...options
};
this.pswp = pswp;
this.initCaption();
}
make change of datasource in my code and pass pswp object to the library as:
options.dataSource = Array.from(galleryElements).map(el => ({
src: el.getAttribute('href'),
width: parseInt(el.getAttribute('data-pswp-width')),
height: parseInt(el.getAttribute('data-pswp-height')),
// alt: el.getAttribute('data-caption'),
element: el
}));
const pswp = new PhotoSwipe(options);
const captionPlugin = new PhotoSwipeDynamicCaption(pswp, {
mobileLayoutBreakpoint: 700,
type: 'auto',
mobileCaptionOverlapRatio: 1
});
Each el contains a "pswp-caption-content" class, as usual, to provide caption content to PhotoSwipeDynamicCaption plugin.
I am using Photoswipe without lightbox module (https://photoswipe.com/data-sources/#without-lightbox-module). The example provided here is based on lightbox
How to load PhotoSwipeDynamicCaption with photoswipe? My current code looks like this:
"alt" property in options.dataSource is the caption text.
Thanks.