百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

photoswipe-dynamic-caption-plugin

> 编程语言
开源

PhotoSwipe v5 的动态文字说明插件。自动将文字说明放置在图像旁边或下方。

99 stars0 点赞5 次浏览
访问官网GitHub

工具介绍

PhotoSwipe v5 的动态文字说明插件。自动将文字说明放置在图像旁边或下方。

Dynamic caption plugin for PhotoSwipe v5

**[> Plugin demo { return slide.data.element.querySelector('img').getAttribute('alt'); }


#### `type: 'auto'`

Position type of the caption can be 'auto', 'below', or 'aside'.

- 'below' - caption will always be placed below the image
- 'aside' - caption will always be placed on the right side of the image
- 'auto'  - the plugin will try to automatically determine the best position (depending on available space)

#### `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:
  
```js
mobileLayoutBreakpoint: (pswp, captionPlugin) => {
  return (window.innerWidth < 750);
}

…

css
.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;
}

How 'auto' positioning works

  • Check if there is more horizontal or vertical free space around the image.
  • If there is more free vertical space:
    • Set caption width to the width of the image
    • Add pswp__dynamic-caption--below class, so the size can also be adjusted via CSS.
    • Measure caption height.
    • Check if the caption will fit without any adjustments to the image position.
      • If it does - just show the caption below the image.
      • If it doesn't - reduce the pan area height by the height of the caption.
  • If there is more horizontal space:
    • Add pswp__dynamic-caption--aside class, so the size can be adjusted via CSS.
    • Measure caption width.
    • Check if caption will fit on the right side without any adjustments of image position.
      • If it does - just show the caption aside from the image.
      • If it doesn't - reduce the pan area width by the width of the caption.

If mobileLayoutBreakpoint requirements are met:

  • Measure caption height when it occupies 100% of width.
  • Reduce pan area height to fit the caption below the image.
  • Check the amount of free horizontal space after the adjustment.
  • If there is too much horizontal space (mobileCaptionOverlapRatio) - just overlap the caption and keep the image at the default position.

Changelog

1.2.0

  • Requires PhotoSwipe 5.3.0.
  • Caption now moves with the slide when dragged (instead of fading in and out).
  • Each slide now has a separate DOM element (before there was only a single caption element that changed content).
  • No longer uses temporary caption to measure size.
  • You may now access caption and its data via dynamicCaption property of a slide. For example pswp.currSlide.dynamicCaption.

1.1.0

  • No longer adjusts main image padding. If you need to dynamically change padding based on the screen size - use PhotoSwipe option paddingFn (introduced in 5.1.61)
  • Caption receives class pswp__dynamic-caption--on-hor-edge when it's on horizontal edge (x position is less than threshold). Added option horizontalEdgeThreshold to control this.
  • Reworked mobile layout. Now the caption tries to not overlap the main image if there is an empty space below. Added option mobileCaptionOverlapRatio to control this.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptphotoswipe

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言