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.
THE original Lightbox script (v2).
JavaScript image viewer.
Quick Overview
lightGallery is a customizable, modular, and responsive JavaScript gallery plugin. It supports touch events, various transition effects, and can display images, videos, and inline content. The plugin is designed to work seamlessly across different devices and browsers.
Pros
- Highly customizable with numerous options and API methods
- Supports various media types including images, videos, and inline content
- Responsive design and touch-friendly for mobile devices
- Modular architecture allows for easy extension and customization
Cons
- Large file size when including all features and modules
- Learning curve for advanced customization and API usage
- Some users report occasional performance issues with large galleries
- Limited built-in themes, requiring custom CSS for unique designs
Code Examples
- Basic image gallery setup:
import lightGallery from 'lightgallery';
lightGallery(document.getElementById('gallery-container'), {
speed: 500,
download: false
});
- Video gallery with YouTube and Vimeo support:
import lightGallery from 'lightgallery';
import lgVideo from 'lightgallery/plugins/video';
lightGallery(document.getElementById('video-gallery'), {
plugins: [lgVideo],
videojs: true,
videojsOptions: {
muted: true
}
});
- Dynamic gallery with custom slide HTML:
import lightGallery from 'lightgallery';
const lg = lightGallery(document.getElementById('dynamic-gallery'), {
dynamic: true,
dynamicEl: [
{
src: 'img/1.jpg',
subHtml: '<h4>Custom Caption</h4><p>Description here</p>'
},
{
html: '<div class="custom-html">Inline content</div>'
}
]
});
Getting Started
-
Install lightGallery:
npm install lightgallery
-
Import and initialize:
import lightGallery from 'lightgallery'; import 'lightgallery/css/lightgallery.css'; lightGallery(document.getElementById('gallery-container'), { // options here });
-
Add HTML structure:
<div id="gallery-container"> <a href="img/1.jpg"> <img src="img/thumb1.jpg" /> </a> <a href="img/2.jpg"> <img src="img/thumb2.jpg" /> </a> </div>
Competitor Comparisons
JavaScript image gallery for mobile and desktop, modular, framework independent
Pros of PhotoSwipe
- Lightweight and fast, with a smaller file size
- More customizable with a modular architecture
- Better support for mobile devices and touch gestures
Cons of PhotoSwipe
- Steeper learning curve due to its modular nature
- Less out-of-the-box features compared to lightGallery
- Requires more setup and configuration for advanced functionality
Code Comparison
PhotoSwipe initialization:
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
lightGallery initialization:
lightGallery(document.getElementById('lightgallery'), {
plugins: [lgZoom, lgThumbnail],
speed: 500
});
Both libraries offer powerful image gallery functionality, but they cater to different needs. PhotoSwipe is more lightweight and customizable, making it ideal for developers who want fine-grained control over their gallery implementation. On the other hand, lightGallery provides a more feature-rich experience out of the box, with easier setup for common use cases.
PhotoSwipe's modular architecture allows for better performance optimization, but it comes at the cost of a steeper learning curve. lightGallery offers a wider range of built-in features and plugins, making it more suitable for quick implementations and projects that require diverse gallery functionalities without extensive customization.
A touchable jQuery lightbox
Pros of Swipebox
- Lightweight and simple to implement
- Mobile-friendly with touch swipe support
- Minimal dependencies (only requires jQuery)
Cons of Swipebox
- Less feature-rich compared to lightGallery
- Limited customization options
- Not actively maintained (last update in 2017)
Code Comparison
Swipebox initialization:
$(document).ready(function() {
$('.swipebox').swipebox();
});
lightGallery initialization:
$(document).ready(function() {
$('#lightgallery').lightGallery();
});
Both libraries offer simple initialization, but lightGallery provides more options for customization and advanced features.
Summary
Swipebox is a lightweight and mobile-friendly option for creating image galleries, but it lacks the extensive features and active development of lightGallery. While Swipebox is easier to implement for simple use cases, lightGallery offers more flexibility and customization options for complex projects. The choice between the two depends on the specific requirements of your project and the level of functionality you need.
:zap: Simple and easy to use lightbox script written in pure JavaScript
Pros of baguetteBox.js
- Lightweight and minimalistic, 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's extensive options
- Less customization possibilities for advanced use cases
- Fewer animation and transition effects available
Code Comparison
baguetteBox.js:
baguetteBox.run('.gallery', {
animation: 'fadeIn',
noScrollbars: true
});
lightGallery:
lightGallery(document.getElementById('gallery'), {
plugins: [lgZoom, lgThumbnail],
speed: 500,
download: false
});
Both libraries offer easy initialization, but lightGallery provides more options and plugin support out of the box. baguetteBox.js focuses on simplicity, while lightGallery offers greater flexibility and features.
baguetteBox.js is ideal for projects requiring a basic, lightweight lightbox solution without extra bells and whistles. lightGallery is better suited for more complex gallery needs, offering extensive customization and additional features like video support, thumbnails, and various plugins.
Choose baguetteBox.js for simplicity and small file size, or opt for lightGallery when advanced functionality and customization are priorities.
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
Pros of Fancybox
- More lightweight and faster loading times
- Easier to set up and configure for basic use cases
- Better touch support for mobile devices
Cons of Fancybox
- Less customizable compared to LightGallery
- Fewer built-in features and plugins
- Limited free version, with more advanced features requiring a paid license
Code Comparison
LightGallery:
lightGallery(document.getElementById('gallery'), {
plugins: [lgZoom, lgThumbnail],
speed: 500,
download: false
});
Fancybox:
Fancybox.bind("[data-fancybox]", {
loop: true,
buttons: ["zoom", "slideShow", "fullScreen", "close"],
animationEffect: "fade"
});
Both libraries offer easy-to-use initialization methods, but LightGallery provides more granular control over plugins and options. Fancybox's syntax is slightly more concise for basic setups.
LightGallery excels in customization and feature-rich galleries, while Fancybox focuses on simplicity and performance. The choice between them depends on project requirements, with LightGallery being more suitable for complex implementations and Fancybox for straightforward image viewing needs.
THE original Lightbox script (v2).
Pros of Lightbox2
- Lightweight and simple to implement
- Long-standing project with a large user base
- No dependencies, pure JavaScript
Cons of Lightbox2
- Limited features compared to LightGallery
- Less frequent updates and maintenance
- Fewer customization options
Code Comparison
Lightbox2:
lightbox.option({
'resizeDuration': 200,
'wrapAround': true
});
LightGallery:
lightGallery(document.getElementById('gallery-container'), {
plugins: [lgZoom, lgThumbnail],
speed: 500,
download: false
});
Feature Comparison
- LightGallery offers more advanced features like video support, thumbnails, and fullscreen mode
- Lightbox2 focuses on simplicity and ease of use for basic image lightbox functionality
- LightGallery provides better mobile support and touch gestures
Performance
- Lightbox2 has a smaller file size, which can lead to faster load times for simple use cases
- LightGallery's modular structure allows for better optimization in complex implementations
Community and Support
- Both projects have active communities, but LightGallery tends to have more frequent updates and contributions
- Lightbox2's simplicity results in fewer reported issues and easier troubleshooting
Conclusion
Choose Lightbox2 for simple, lightweight image lightbox needs. Opt for LightGallery when requiring advanced features, extensive customization, or support for various media types.
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 feature set compared to lightGallery
- Fewer customization options and themes
- Less active development and community support
Code Comparison
Viewer.js initialization:
const viewer = new Viewer(document.getElementById('images'));
lightGallery initialization:
lightGallery(document.getElementById('gallery'), {
plugins: [lgZoom, lgThumbnail],
speed: 500
});
Both libraries offer straightforward initialization, but lightGallery provides more options for customization directly in the initialization code.
Viewer.js focuses on a minimalist approach, making it easier to set up for basic image viewing needs. However, lightGallery offers a more comprehensive set of features and plugins, allowing for greater flexibility in creating advanced gallery experiences.
While Viewer.js excels in simplicity and lightweight implementation, lightGallery provides a more robust solution for complex gallery requirements, including video support, thumbnails, and various animation effects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
lightGallery
A customizable, modular, responsive, lightbox gallery plugin. No dependencies.\ Available for React.js, Angular, Vue.js, and typescript.
Core features
- Fully responsive.
- Modular architecture with built in plugins.
- Highly optimized for touch devices.
- Mouse drag supports for desktops.
- Double-click/Double-tap to see actual size of the image.
- Animated thumbnails.
- Social sharing.
- YouTube Vimeo Wistia and html5 videos Support.
- 20+ Hardware-Accelerated CSS3 transitions.
- Dynamic mode.
- Inline gallery.
- Full screen support.
- Zoom in/out, Pinch to zoom.
- Swipe/Drag up/down support to close gallery.
- Browser history API(deep linking).
- 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.
- SVG icons.
- Accessibility support.
- Rotate, flip images.
- And many more.
Documentation
Installation
lightGallery is available on NPM, Yarn, Bower, CDNs, and GitHub. You can use any of the following method to download lightGallery.
-
NPM - NPM is a package manager for the JavaScript programming language. You can install
lightgallery
using the following commandnpm install lightgallery
-
YARN - Yarn is another popular package manager for the JavaScript programming language. If you prefer you can use Yarn instead of NPM
yarn add lightgallery
-
Bower - You can find lightGallery on Bower package manager as well
bower install lightgallery --save
-
GitHub - You can also directly download lightgallery from GitHub
-
CDN - If you prefer to use a CDN, you can load files via jsdelivr, cdnjs or unpkg
Include CSS and Javascript files
First of all, include lightgallery.css in the <head> of the document. If you want include any lightGallery plugin such as thumbnails or zoom, you need to include respective css files as well.
Alternatively you can include lightgallery-bundle.css
which contains
lightGallery and all plugin styles instead of separate stylesheets.
If you like you can also import scss files instead of css files from the scss
folder.
<head>
<link type="text/css" rel="stylesheet" href="css/lightgallery.css" />
<!-- lightgallery plugins -->
<link type="text/css" rel="stylesheet" href="css/lg-zoom.css" />
<link type="text/css" rel="stylesheet" href="css/lg-thumbnail.css" />
<!-- OR -->
<link type="text/css" rel="stylesheet" href="css/lightgallery-bundle.css" />
</head>
Then include lightgallery.umd.js into your document. If you want to include any lightgallery plugin you can include it after lightgallery.umd.js.
<body>
....
<script src="js/lightgallery.umd.js"></script>
<!-- lightgallery plugins -->
<script src="js/plugins/lg-thumbnail.umd.js"></script>
<script src="js/plugins/lg-zoom.umd.js"></script>
</body>
lightGallery supports AMD, CommonJS and ES6 modules too.
import lightGallery from 'lightgallery';
// Plugins
import lgThumbnail from 'lightgallery/plugins/thumbnail'
import lgZoom from 'lightgallery/plugins/zoom'
The markup
lightgallery does not force you to use any kind of markup. you can use whatever markup you want. Here can find detailed examples of different kinds of markups.
If you know the original size of the media, you can pass it via
data-lg-size="${width}-${height}"
attribute for the initial
zoom animation.
But, this is completely optional.
<div id="lightgallery">
<a href="img/img1.jpg" data-lg-size="1600-2400">
<img alt=".." src="img/thumb1.jpg" />
</a>
<a href="img/img2.jpg" data-lg-size="1024-800">
<img alt=".." src="img/thumb2.jpg" />
</a>
...
</div>
Initialize lightGallery
Finally, you need to initiate the gallery by adding the following code.
<script type="text/javascript">
lightGallery(document.getElementById('lightgallery'), {
plugins: [lgZoom, lgThumbnail],
speed: 500,
licenseKey: 'your_license_key'
... other settings
});
</script>
License Key
You'll receive a license key via email one you purchase a license More info
Plugins
As shown above, you need to pass the plugins via settings if you want to use any lightGallery plugins.
If you are including lightGallery files via script tag, please use the same plugins names as follows.
lgZoom
, lgAutoplay
, lgComment
, lgFullscreen
, lgHash
, lgPager
,
lgRotate
, lgShare
, lgThumbnail
, lgVideo
, lgMediumZoom
Browser support
lightGallery supports all major browsers including IE 10 and above.
License
Commercial license
If you want to use lightGallery 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.
Support
If you have any questions, suggestions, feedback, please reach out to contact@lightgalleryjs.com or DM me on twitter
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.
THE original Lightbox script (v2).
JavaScript image viewer.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot