Là một dự án mã nguồn mở, dimsemenov/photoswipe-dynamic-caption-plugin đã đạt 101 sao trên GitHub, ngôn ngữ JavaScript. A dynamic caption plugin for PhotoSwipe v5. Automatically positions the caption aside or below the image.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
Initialization
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 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>
Also refer the source of the demo page - index.html.
Plugin options
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.
When the 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 an "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 constantly shift the image (unless it's taller than the viewport).
verticallyCenterImage: false
If enabled, the image will always be vertically centered in the remaining space between the caption and the rest of the viewport. If set to false (default value) - the image will lift up only if the caption does not fit below.
Styling
The caption has class pswp__dynamic-caption.
It can be in one of these states:
Below the main image - pswp__dynamic-caption--below.
Right side of the main image - pswp__dynamic-caption--aside.
"Mobile" (by default just pinned to bottom) - pswp__dynamic-caption--mobile
If the caption is near the 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 to):
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.
dimsemenov/photoswipe-dynamic-caption-plugin có bao nhiêu sao?
dimsemenov/photoswipe-dynamic-caption-plugin có 101 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/dimsemenov/photoswipe-dynamic-caption-plugin. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
dimsemenov/photoswipe-dynamic-caption-plugin có những chủ đề gì?
GitHub topics của dimsemenov/photoswipe-dynamic-caption-plugin: "photoswipe". TopGit xếp repo vào nhóm mã nguồn mở.
dimsemenov/photoswipe-dynamic-caption-plugin có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho dimsemenov/photoswipe-dynamic-caption-plugin. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
dimsemenov/photoswipe-dynamic-caption-plugin còn đang phát triển không?
Commit gần nhất trên dimsemenov/photoswipe-dynamic-caption-plugin là 2.7 năm trước (theo timestamp GitHub). Repo có 13 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
dimsemenov/photoswipe-dynamic-caption-plugin dùng license gì?
dimsemenov/photoswipe-dynamic-caption-plugin phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
dimsemenov/photoswipe-dynamic-caption-plugin viết bằng ngôn ngữ gì?
dimsemenov/photoswipe-dynamic-caption-plugin chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về dimsemenov/photoswipe-dynamic-caption-plugin ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/dimsemenov/photoswipe-dynamic-caption-plugin là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc photoswipe-dynamic-caption-plugin có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về photoswipe-dynamic-caption-plugin.