Skills2026年5月18日·1 分钟阅读

PhotoSwipe — JavaScript Image Gallery and Lightbox

A dependency-free JavaScript image gallery and lightbox with touch gestures, zoom, and progressive loading for fast, responsive image browsing.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
PhotoSwipe
直接安装命令
npx -y tokrepo@latest install ec80d008-524e-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

PhotoSwipe is a JavaScript image gallery and lightbox that provides a native-app-like experience on the web. It supports pinch-to-zoom, swipe navigation, and progressive image loading with no dependencies and a small footprint.

What PhotoSwipe Does

  • Opens images in a full-screen lightbox overlay with smooth zoom and pan
  • Supports swipe gestures for navigation and pinch-to-zoom on touch devices
  • Loads images progressively, showing thumbnails first then swapping in full-resolution versions
  • Provides a responsive design that adapts to any screen size and orientation
  • Handles image captions, sharing controls, and custom toolbar buttons

Architecture Overview

PhotoSwipe v5 uses a modular ES module design. The lightbox module handles gallery initialization and event delegation on thumbnail links. The core module manages the slide viewport, gesture recognition, and zoom state machine. CSS animations power transitions with GPU-accelerated transforms. Images are lazy-loaded on demand, and the dynamic import pattern keeps the initial bundle small until the lightbox is first opened.

Self-Hosting & Configuration

  • Install via npm or include from a CDN; import both the JS module and CSS stylesheet
  • Mark gallery links with data-pswp-width and data-pswp-height attributes for layout calculation
  • Configure options like bgOpacity, zoom, showHideAnimationType, and padding
  • Add custom UI elements by extending the lightbox with pswp.ui.registerElement()
  • Integrate with frameworks by calling lightbox.init() after the DOM is ready or in a lifecycle hook

Key Features

  • Zero dependencies with a ~5KB gzipped core plus dynamically loaded lightbox module
  • Native-feeling gestures: pinch-to-zoom, swipe to close, and momentum-based panning
  • URL-based deep linking so individual images can be shared and bookmarked
  • Accessibility support with keyboard navigation and ARIA labels
  • Plugin API for custom slides (video, HTML content) and toolbar extensions

Comparison with Similar Tools

  • Lightbox2 — jQuery-based, simpler but no touch gestures or zoom; PhotoSwipe is modern and dependency-free
  • GLightbox — Lightweight with video support; PhotoSwipe has better zoom and gesture handling
  • Fancybox — Feature-rich but requires a commercial license; PhotoSwipe is MIT-licensed
  • Magnific Popup — jQuery plugin, no longer maintained; PhotoSwipe is actively developed
  • medium-zoom — Single-image zoom effect; PhotoSwipe provides full gallery navigation

FAQ

Q: Does PhotoSwipe require jQuery? A: No. Version 5 is a standalone ES module with zero dependencies.

Q: Can I display videos in PhotoSwipe? A: Yes. Use the content API to register a custom slide type that renders a video element or iframe inside the lightbox.

Q: How does deep linking work? A: PhotoSwipe updates the URL hash with the current slide index. Users can share the URL to link directly to a specific image in the gallery.

Q: Is PhotoSwipe accessible? A: Yes. It supports full keyboard navigation (arrow keys, Escape to close), focus trapping within the lightbox, and ARIA labels on controls.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产