Convert Figma logo to code with AI

sachinchoolur logolightgallery.js

Full featured JavaScript image & video gallery. No dependencies

5,302
596
5,302
0

Top Related Projects

JavaScript image gallery for mobile and desktop, modular, framework independent

A touchable jQuery lightbox

:zap: Simple and easy to use lightbox script written in pure JavaScript

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

JavaScript image viewer.

THE original Lightbox script (v2).

Quick Overview

lightgallery.js is a full-featured, lightweight JavaScript library for creating beautiful and responsive image and video galleries. It supports touch navigation, zoom, and various transition effects, making it ideal for creating interactive media galleries on websites and web applications.

Pros

  • Lightweight and fast-loading, with no jQuery dependency
  • Supports a wide range of media types, including images, videos, and iframes
  • Highly customizable with numerous options and plugins
  • Responsive design and touch-friendly for mobile devices

Cons

  • Limited built-in themes, requiring custom CSS for advanced styling
  • Some users report occasional performance issues with large galleries
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Basic gallery initialization:
lightGallery(document.getElementById('gallery-container'));
  1. Gallery with custom options:
lightGallery(document.getElementById('gallery-container'), {
    speed: 500,
    download: false,
    counter: false,
    thumbnail: true
});
  1. Dynamic gallery creation:
const dynamicGallery = [
    {
        src: 'https://example.com/image1.jpg',
        thumb: 'https://example.com/thumb1.jpg',
        subHtml: '<h4>Image 1</h4><p>Description for Image 1</p>'
    },
    {
        src: 'https://example.com/image2.jpg',
        thumb: 'https://example.com/thumb2.jpg',
        subHtml: '<h4>Image 2</h4><p>Description for Image 2</p>'
    }
];

const dynamicGalleryInstance = lightGallery(document.getElementById('dynamic-gallery-container'), {
    dynamic: true,
    dynamicEl: dynamicGallery
});

Getting Started

  1. Include the lightgallery.js script and CSS in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/css/lightgallery.min.css">
<script src="https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/lightgallery.min.js"></script>
  1. Create a container for your gallery:
<div id="gallery-container">
    <a href="image1.jpg"><img src="thumb1.jpg" alt="Image 1"></a>
    <a href="image2.jpg"><img src="thumb2.jpg" alt="Image 2"></a>
    <a href="image3.jpg"><img src="thumb3.jpg" alt="Image 3"></a>
</div>
  1. Initialize the gallery:
lightGallery(document.getElementById('gallery-container'));

Competitor Comparisons

JavaScript image gallery for mobile and desktop, modular, framework independent

Pros of PhotoSwipe

  • Lightweight and fast, with minimal dependencies
  • Supports touch gestures and smooth animations
  • Highly customizable with extensive API and options

Cons of PhotoSwipe

  • Less feature-rich compared to LightGallery.js
  • Requires more manual setup and configuration
  • Limited built-in social sharing options

Code Comparison

PhotoSwipe:

var pswpElement = document.querySelectorAll('.pswp')[0];
var items = [
    { src: 'image1.jpg', w: 1200, h: 900 },
    { src: 'image2.jpg', w: 1200, h: 900 }
];
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();

LightGallery.js:

<div id="lightgallery">
    <a href="image1.jpg"><img src="thumb1.jpg" /></a>
    <a href="image2.jpg"><img src="thumb2.jpg" /></a>
</div>
<script>
    lightGallery(document.getElementById('lightgallery'));
</script>

Both libraries offer responsive image galleries, but PhotoSwipe focuses on simplicity and performance, while LightGallery.js provides more built-in features and easier setup. PhotoSwipe requires manual item definition and initialization, whereas LightGallery.js can work with minimal markup and automatically detects gallery items.

A touchable jQuery lightbox

Pros of Swipebox

  • Lightweight and simple to implement
  • Supports touch gestures for mobile devices
  • Minimal dependencies (only requires jQuery)

Cons of Swipebox

  • Less feature-rich compared to LightGallery.js
  • Limited customization options
  • Not actively maintained (last update in 2017)

Code Comparison

Swipebox initialization:

$(document).ready(function() {
  $('.swipebox').swipebox();
});

LightGallery.js initialization:

lightGallery(document.getElementById('lightgallery'), {
  plugins: [lgZoom, lgThumbnail],
  speed: 500
});

Both libraries offer simple initialization, but LightGallery.js provides more options for customization and plugin support out of the box.

Swipebox is a lightweight solution for basic image gallery needs, particularly suitable for mobile-friendly websites. It's easy to implement but lacks advanced features and customization options.

LightGallery.js, on the other hand, offers a more comprehensive set of features, including video support, thumbnails, and various animation effects. It's actively maintained and provides better documentation and community support.

For simple projects with basic gallery requirements, Swipebox might be sufficient. However, for more complex implementations or projects requiring extensive customization, LightGallery.js would be the better choice.

:zap: Simple and easy to use lightbox script written in pure JavaScript

Pros of baguetteBox.js

  • Lightweight and minimal, with a smaller file size
  • No dependencies, making it easier to integrate
  • Simple and straightforward API for basic lightbox functionality

Cons of baguetteBox.js

  • Limited features compared to lightgallery.js
  • Less customization options for advanced use cases
  • Fewer animation and transition effects available

Code Comparison

baguetteBox.js:

baguetteBox.run('.gallery', {
    animation: 'fadeIn',
    noScrollbars: true
});

lightgallery.js:

lightGallery(document.getElementById('lightgallery'), {
    mode: 'lg-fade',
    cssEasing: 'cubic-bezier(0.25, 0, 0.25, 1)',
    thumbnail: true,
    animateThumb: false,
    showThumbByDefault: false
});

The code comparison shows that baguetteBox.js has a simpler initialization process with fewer options, while lightgallery.js offers more advanced configuration possibilities out of the box. lightgallery.js provides more granular control over animations, thumbnails, and other features, making it suitable for more complex gallery implementations. baguetteBox.js, on the other hand, focuses on simplicity and ease of use for basic lightbox functionality.

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

Pros of Fancybox

  • More polished and user-friendly interface out of the box
  • Better support for touch devices and mobile responsiveness
  • Easier to implement and customize for beginners

Cons of Fancybox

  • Smaller community and fewer contributors compared to Lightgallery.js
  • Less flexible for advanced customizations and unique use cases
  • Paid license required for commercial use

Code Comparison

Lightgallery.js:

lightGallery(document.getElementById('lightgallery'), {
    plugins: [lgZoom, lgThumbnail],
    speed: 500,
    download: false
});

Fancybox:

Fancybox.bind("[data-fancybox]", {
    loop: true,
    buttons: ["zoom", "slideShow", "fullScreen", "close"],
    animationEffect: "fade"
});

Both libraries offer simple initialization, but Fancybox's syntax is slightly more concise. Lightgallery.js requires explicit plugin imports, while Fancybox includes most features by default. Fancybox's options are more intuitive for common use cases, but Lightgallery.js offers more granular control over plugins and settings.

JavaScript image viewer.

Pros of Viewer.js

  • Lightweight and focused on image viewing functionality
  • Simple API and easy integration
  • Supports mobile touch gestures out of the box

Cons of Viewer.js

  • Limited features compared to LightGallery.js
  • Fewer customization options for UI and controls
  • Less active development and community support

Code Comparison

Viewer.js initialization:

const viewer = new Viewer(document.getElementById('images'));

LightGallery.js initialization:

lightGallery(document.getElementById('lightgallery'), {
  plugins: [lgZoom, lgThumbnail],
  speed: 500
});

Viewer.js offers a more straightforward initialization process, while LightGallery.js provides more options for customization right from the start.

Both libraries serve the purpose of creating image galleries, but they cater to different needs. Viewer.js is ideal for simple image viewing requirements, while LightGallery.js is better suited for feature-rich gallery implementations with extensive customization options.

The choice between the two depends on the specific project requirements, desired features, and the level of complexity needed in the image gallery implementation.

THE original Lightbox script (v2).

Pros of Lightbox2

  • Lightweight and simple to implement
  • Extensive browser compatibility, including older versions
  • Well-documented with clear usage instructions

Cons of Lightbox2

  • Limited features compared to Lightgallery.js
  • Less customization options for advanced users
  • Fewer animation and transition effects

Code Comparison

Lightbox2:

lightbox.option({
  'resizeDuration': 200,
  'wrapAround': true
});

Lightgallery.js:

lightGallery(document.getElementById('lightgallery'), {
  mode: 'lg-fade',
  cssEasing: 'cubic-bezier(0.25, 0, 0.25, 1)'
});

Lightbox2 focuses on simplicity, making it easy to set up with minimal configuration. Lightgallery.js offers more advanced options and customization, allowing for greater control over the gallery's appearance and behavior.

While Lightbox2 is ideal for basic image viewing needs, Lightgallery.js provides a more feature-rich experience with support for various media types and advanced gallery controls. The choice between the two depends on the project's requirements and the desired level of customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

lightgallery.js

travis bower npm

Full featured JavaScript lightbox gallery. No dependencies.

lightgallery

Important notice

  • lightgallery.js has been merged with lightGallery. That means, v2 of lightgallery.js is https://www.lightgalleryjs.com/. if you have a lightgallery.js license, this is valid for lightGallery as well. But, since version 2.0 you need to pass the license key as a plugin option. If you alredy have a license, please contact me at contact@lightgallery.js for the license key
  • Completely re-wrote from scratch in typescript
  • Moved all modules to the main repo for better maintainability.
  • Dropped IE 8 and 9 support. Let me know if you still need support for IE 8 and 9. I’ll consider adding a plugin to add support if there is enough demand.
  • Website
  • Docs
  • Demos
Any questions, ideas, suggestions about v2? please start a discussion.

New features

  • Pinch to zoom
  • Virtual slides
  • Swipe to close
  • Zoom from the origin
  • Inline gallery
  • Next-generation image formats support(webp, JPEG XL). etc
  • Better customizability
  • Better performance on mobile devices.
  • Dynamically add, remove slides while the gallery is open
  • Comment interface
  • and much more.

How to upgrade

To make the upgrade seamless, v2 follows the API structure as much as possible. But, few settings are removed and a lot of additional settings are added, the way we use public methods is changed slightly and few events are renamed.

Initialization V2 doesn’t require jQuery as a dependancy.

lightGallery(document.getElementById('lightgallery'), {
  plugins: [lgZoom, lgThumbnail,]
  speed: 500
  ... other settings
});

Plugins To avoid polluting global scope, since v2 plugins has to be passed via settings.

lightGallery(document.getElementById(‘’lightgallery), {
    
plugins: [lgZoom, lgAutoplay, lgComment, lgFullscreen , lgHash, lgPager, lgRotate, lgShare, lgThumbnail, lgVideo]

});
  • Removed in-built support for Dailymotion VK. We Will be adding separate plugins for DailyMotion and VK support
  • Added Wistia support
  • HTML videos - Videos can be passed via data-video attribute instead of passing it via hidden div
data-video='{"source": [{"src":"/videos/video1.mp4", "type":"video/mp4"}], "attributes": {"preload": false, "controls": true}}'
  • Events are renamed - Please take a look at the documentation
  • Few settings are added, removed, or renamed. Rather than listing down all the changes here, I’d recommend going through the current settings that you are using and compare them with the new documentation.



Main features

  • Fully responsive.
  • Modular architecture with built in plugins.
  • Touch support for mobile devices.
  • Mouse drag supports for desktops.
  • Double-click/Double-tap to see actual size of the image.
  • Animated thumbnails.
  • Social media sharing.
  • YouTube, Vimeo, Dailymotion, VK and HTML5 video support.
  • 20+ Hardware-Accelerated CSS3 transitions.
  • Dynamic mode.
  • Full screen support.
  • Supports zoom.
  • Browser history API.
  • Responsive images.
  • HTML iframe support.
  • Multiple instances on one page.
  • Easily customizable via CSS (SCSS) and Settings.
  • Smart image preloading and code optimization.
  • Keyboard Navigation for desktop.
  • Font icon support.
  • Rotate, flip images.
  • Accessibility support.
  • And many more.

Browser support

lightgallery supports all major browsers including IE 9 and above.

Installation

Install with NPM

You can install lightgallery.js using the npm package manager.

npm install lightgallery.js

You can also find lightgallery.js on Yarn and Bower.

Yarn

yarn add lightgallery.js

Bower

bower install lightgallery.js --save

CDN

http://www.jsdelivr.com/projects/lightgallery.js

Download from GitHub

You can also directly download lightgallery from GitHub.

Include CSS and JavaScript files

First of all add lightgallery.css in the <head> of the document.

<head>
    <link rel="stylesheet" href="css/lightgallery.css">
</head>

Then include lightgallery.min.js into your document. If you want to include any lightgallery plugin you can include it after lightgallery.min.js.

<body>
    ...

    <script src="js/lightgallery.min.js"></script>

    <!-- lightgallery plugins -->
    <script src="js/lg-thumbnail.min.js"></script>
    <script src="js/lg-fullscreen.min.js"></script>
</body>

Lightgallery also supports AMD, CommonJS and ES6 modules. When you use AMD make sure that lightgallery.js is loaded before lightgallery modules.

require(['./lightgallery.js'], function() {
    require(["./lg-zoom.js", "./lg-thumbnail.js"], function(){
        lightGallery(document.getElementById('lightgallery'));
    });
});

The markup

lightgallery does not force you to use any kind of markup. You can use whatever markup you want. But i suggest you to use the following markup. Here you can find the detailed examples of different kinds of markup.

<div id="lightgallery">
    <a href="img/img1.jpg">
        <img src="img/thumb1.jpg">
    </a>
    <a href="img/img2.jpg">
        <img src="img/thumb2.jpg">
    </a>
    ...
</div>

Call the plugin

Finally you need to initiate the gallery by adding the following code.

<script>
    lightGallery(document.getElementById('lightgallery'));
</script>

Support lightgallery

If you like lightgallery please support the project by staring the repository or tweet about this project.

Resources

Demos

Built in modules

  1. Thumbnail - GItHub - Docs
  2. Autoplay - GItHub - Docs
  3. Video - GItHub - Docs
  4. Fullscreen - GItHub - Docs
  5. Pager - GItHub - Docs
  6. Zoom - GItHub - Docs
  7. Hash - GItHub - Docs
  8. Share - GItHub - Docs
  9. Rotate - GItHub - Docs

License

Commercial license

If you want to use lightgallery.js to develop commercial sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Read more about the commercial license

Open source license

If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use this project under the terms of the GPLv3.

NPM DownloadsLast 30 Days