跳到正文
Skillpedia
网站与界面(前端)7.1k · #13596

lightgallery

它能做什么

这项技能指导智能体在使用纯 JavaScript、React、Vue 或 Angular 构建的网站中添加 lightGallery 查看器。它说明应安装哪个包、应引入哪些插件和样式,以及最常导致问题的设置。

适用场景

  • ✓当你希望网站上的照片画廊能在全屏查看器中打开图片的时候。
  • ✓当你需要在画廊中使用缩放、缩略图条,或 YouTube 和 Vimeo 视频时。
  • ✓当网站上的画廊损坏或行为异常,并且你希望智能体找出原因的时候。

技能链接

https://github.com/sachinchoolur/lightGallery/blob/main/skills/lightgallery/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sachinchoolur/lightGallery/blob/main/skills/lightgallery/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想在产品页面上做一个带缩略图和缩放功能的照片画廊。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会为你的项目安装合适的 lightGallery 包,并添加你选择的功能。它遵循标准的设置流程,并设定图片尺寸,使打开时的动画显示正常。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

lightGallery

One gallery, four packages with the same features and settings:

Stack Package Plugins import path
Vanilla JS / TypeScript lightgallery lightgallery/plugins/<name>
React @lightgallery/react @lightgallery/react/plugins/<name>
Vue 3 @lightgallery/vue @lightgallery/vue/plugins/<name>
Angular @lightgallery/angular @lightgallery/angular/plugins/<name>

Plugin names: thumbnail, zoom, video, autoplay, fullscreen, share, hash, rotate, pager, comment, mediumZoom, relativeCaption, vimeoThumbnail, originCrop, justified. Each is a separate entry — import only what the project uses.

Default recipe. Unless the user asks for something else, every image gallery gets the zoom and thumbnail plugins, their two CSS files, and lgSize: 'WIDTH-HEIGHT' (data-lg-size in markup) on every image item. lgSize is the natural size of the full image; it drives the zoom-from-origin animation, where the slide opens from the clicked thumbnail and closes back to it. Without it the slide fades in. Read the dimensions from the image files, the image optimizer or the CMS rather than dropping the field. Leave a plugin out only when told to.

Two rules that prevent most problems

  1. CSS is a consumer import in every stack. The framework packages ship no CSS. Import lightgallery/css/lightgallery.css plus one file per plugin (lightgallery/css/lg-thumbnail.css, lg-zoom.css, …), or lightgallery/css/lightgallery-bundle.css for everything.
  2. Plugins are opt-in. A feature only exists when its plugin is passed (plugins: [...], plugins={[...]}, :plugins="[...]", [features]="[withX()]"). Its settings are ignored otherwise.

Vanilla JavaScript

import lightGallery from 'lightgallery';
import lgThumbnail from 'lightgallery/plugins/thumbnail';
import lgZoom from 'lightgallery/plugins/zoom';
import 'lightgallery/css/lightgallery.css';
import 'lightgallery/css/lg-thumbnail.css';
import 'lightgallery/css/lg-zoom.css';

const gallery = lightGallery(document.getElementById('gallery'), {
    plugins: [lgZoom, lgThumbnail],
    speed: 400,
});

Markup mode: the container holds anchors; each anchor's href (or data-src) is the full image, the inner <img> is the thumbnail, and data-lg-size="WIDTH-HEIGHT" is the full image's natural size for the zoom-from-origin animation. Captions come from data-sub-html. If items are not direct children, set selector. Dynamic mode: dynamic: true, dynamicEl: [{ src, thumb, lgSize, subHtml }] and call gallery.openGallery(index).

Methods: openGallery(index), closeGallery(), refresh() after the markup changed, destroy(). Events fire on the container element (lgBeforeOpen, lgAfterSlide, …) with data in event.detail; attach listeners before initializing.

React

'use client'; // Next.js App Router: the gallery is a client component
import { LightGallery, LightGalleryItem } from '@lightgallery/react';
import Thumbnail from '@lightgallery/react/plugins/thumbnail';
import Zoom from '@lightgallery/react/plugins/zoom';

// items: [{ src, thumb, alt, lgSize: '1600-1067' }, …]
export function Gallery({ items }) {
    return (
        <LightGallery plugins={[Zoom, Thumbnail]} thumbnail={{ animateThumb: true }}>
            {items.map((item) => (
                <LightGalleryItem key={item.src} item={item}>
                    <img src={item.thumb} alt={item.alt} />
                </LightGalleryItem>
            ))}
        </LightGallery>
    );
}

Import the CSS in the root layout. Plugin settings are objects on props named after the plugin (zoom={{ … }}, thumbnail={{ … }}); bare boolean props are not valid. Callbacks are onAfterSlide, onBeforeOpen, …; the imperative handle (ref) exposes openGallery, closeGallery, goToSlide, nextSlide, prevSlide. Use either the controlled open prop or the uncontrolled default for the component's whole lifetime, not both. The package is SSR-safe; no dynamic(..., { ssr: false }) needed.

Vue 3

<script setup>
import { LightGallery, LgItem } from '@lightgallery/vue';
import Thumbnail from '@lightgallery/vue/plugins/thumbnail';
import Zoom from '@lightgallery/vue/plugins/zoom';

const items = [{ src: '/photos/1.jpg', thumb: '/photos/1-thumb.jpg', alt: 'One', lgSize: '1600-1067' }];
</script>

<template>
    <LightGallery :plugins="[Zoom, Thumbnail]" :thumbnail
常见问题

这个画廊技能涵盖哪些框架?

涵盖纯 JavaScript 和 TypeScript、React、Vue 3 以及 Angular。智能体会使用与你的项目相匹配的包。

为什么我的画廊打开时没有缩放动画?

通常是因为缺少图片的宽度和高度。该技能建议读取每个图片文件的尺寸,使动画能从缩略图开始。

我需要自己添加画廊样式吗?

需要。框架包本身不含样式,因此智能体会把 CSS 文件引入你的项目。

详情

作者的原始描述

Add or configure a lightGallery image/video lightbox or gallery in vanilla JavaScript, React, Vue or Angular — install, imports, plugins, CSS, settings, and the pitfalls that produce most bug reports. Use when a project needs a lightbox, photo gallery, thumbnail strip, zoomable images or a YouTube/Vimeo gallery, or when editing code that imports lightgallery or @lightgallery/*.

repo: sachinchoolur/lightGallery

热度

GitHub 星标
7.1k
排名
#13596
许可证
GPL-3.0
更新时间
2026/10/14

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

相似技能