
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
photoswipe-dynamic-caption-plugin
Advanced tools
A caption plugin for PhotoSwipe v5+ that smartly positions it aside or below the image.
The plugin can automatically position the text below or aside depending on the available space. For small to medium sized captions. And only for images with the default fit
scale mode.
For accessibility, make sure that important captions are always available without PhotoSwipe - either use an alt
attribute on thumbnails or aria-labelledby
.
The plugin has a single JS file photoswipe-dynamic-caption-plugin.esm.js
(UMD version is in the dist/
folder) and a single CSS file photoswipe-dynamic-caption-plugin.css
. Include them directly or via with npm:
npm i photoswipe-dynamic-caption-plugin --save
It can be initialized like this:
<script type="module">
import PhotoSwipeLightbox from 'photoswipe/dist/photoswipe-lightbox.esm.js';
// or 'photoswipe-dynamic-caption-plugin' if using package manager
import PhotoSwipeDynamicCaption from 'https://unpkg.com/photoswipe-dynamic-caption-plugin/photoswipe-dynamic-caption-plugin.esm.js';
const lightbox = new PhotoSwipeLightbox({
gallerySelector: '#gallery',
childSelector: '.pswp-gallery__item',
pswpModule: () => import('photoswipe/dist/photoswipe.esm.js'),
// Optional padding for images,
// note that this is an option of PhotoSwipe, not a plugin
paddingFn: (viewportSize) => {
return {
top: 30, bottom: 30, left: 70, right: 70
}
},
});
const captionPlugin = new PhotoSwipeDynamicCaption(lightbox, {
// Plugins options, for example:
type: 'auto',
});
// make sure you init photoswipe core after plugins are added
lightbox.init();
</script>
<link rel="stylesheet" href="https://unpkg.com/photoswipe-dynamic-caption-plugin/photoswipe-dynamic-caption-plugin.css">
Also refer the source of the demo page - index.html.
captionContent: '.pswp-caption-content'
Used to retrieve caption content.
Can be a selector of the element from which caption content will be retrieved, if the element is not found - the plugin will try to use the thumbnail image alt
attribute.
<a href="path/to/large-image.jpg" data-pswp-width="1024" data-pswp-height="768">
<img src="path/to/thumbnail.jpg" alt="" />
<span class="pswp-caption-content">Caption content</span>
</a>
Or a function that should return caption content. For example:
captionContent: (slide) => {
return slide.data.element.querySelector('img').getAttribute('alt');
}
type: 'auto'
Position type of the caption, can be 'auto', 'below', or 'aside'.
mobileLayoutBreakpoint: 600
Maximum window width at which mobile layout should be used, or a function that should return true if mobile layout should be used. For example:
mobileLayoutBreakpoint: (pswp, captionPlugin) => {
return (window.innerWidth < 750);
}
horizontalEdgeThreshold: 20
When caption x
position is less than this value, it'll get class pswp__dynamic-caption--on-hor-edge
. You may use it to apply different styling, such as horizontal padding.
mobileCaptionOverlapRatio: 0.3
A ratio defines the amount of horizontal empty space before the mobile caption switches to "overlap" layout. For example, if it's set to 0.3 - the caption will start overlapping the image when more than 30% of horizontal space is not occupied by an image. If you set it to 0 - the caption will always overlap. If you set it to 1 - the caption will always shift the image (unless it's taller than viewport).
If enabled, the image will always be vertically centered in the remaining space between caption and the rest of viewport. If set to false (default value) - the image will lift up only if caption does not fit below.
The caption has class pswp__dynamic-caption
.
It can be in one of these states:
pswp__dynamic-caption--below
.pswp__dynamic-caption--aside
.pswp__dynamic-caption--mobile
If the caption is near left horizontal edge - it gets class pswp__dynamic-caption--on-hor-edge
.
Feel free to adjust styles in the plugin CSS file (and use media queries if you need):
.pswp__dynamic-caption--aside {
max-width: 300px;
padding: 20px 15px 20px 20px;
margin-top: 70px;
}
.pswp__dynamic-caption--below {
max-width: 700px;
padding: 15px 0 0;
}
.pswp__dynamic-caption--mobile {
background: rgba(0, 0, 0, 0.5);
padding: 10px 15px;
}
pswp__dynamic-caption--below
class, so size can also be adjusted via CSS.pswp__dynamic-caption--aside
class, so size can be adjusted via CSS.If mobileLayoutBreakpoint
requirements are met:
mobileCaptionOverlapRatio
) - just overlap the caption and keep the image at the default position.dynamicCaption
property of a slide. For example pswp.currSlide.dynamicCaption
.paddingFn
(introduced in 5.1.61)pswp__dynamic-caption--on-hor-edge
when it's on horizontal edge (x
position is less than threshold). Added option horizontalEdgeThreshold
to control this.mobileCaptionOverlapRatio
to control this.FAQs
A caption plugin for PhotoSwipe v5+ that smartly positions it aside or below the image.
The npm package photoswipe-dynamic-caption-plugin receives a total of 11,498 weekly downloads. As such, photoswipe-dynamic-caption-plugin popularity was classified as popular.
We found that photoswipe-dynamic-caption-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.