What is photoswipe?
PhotoSwipe is a JavaScript library for creating image galleries that work on both desktop and mobile devices. It provides a responsive, touch-friendly interface for viewing images, with features like zooming, panning, and fullscreen mode.
What are photoswipe's main functionalities?
Basic Gallery Setup
This code sets up a basic PhotoSwipe gallery with two images. It initializes the gallery with default options.
const PhotoSwipe = require('photoswipe');
const PhotoSwipeUI_Default = require('photoswipe/dist/photoswipe-ui-default');
const items = [
{
src: 'path/to/image1.jpg',
w: 600,
h: 400
},
{
src: 'path/to/image2.jpg',
w: 1200,
h: 900
}
];
const options = {};
const gallery = new PhotoSwipe(document.querySelectorAll('.pswp')[0], PhotoSwipeUI_Default, items, options);
gallery.init();
Custom Options
This code demonstrates how to customize the PhotoSwipe gallery with options like starting index, background opacity, and disabling the share element.
const options = {
index: 0, // start at first slide
showHideOpacity: true,
bgOpacity: 0.7,
shareEl: false
};
const gallery = new PhotoSwipe(document.querySelectorAll('.pswp')[0], PhotoSwipeUI_Default, items, options);
gallery.init();
Event Handling
This code shows how to add event listeners to the PhotoSwipe gallery for events like image load completion and gallery closure.
gallery.listen('imageLoadComplete', function(index, item) {
console.log('Image loaded:', item.src);
});
gallery.listen('close', function() {
console.log('Gallery closed');
});
Other packages similar to photoswipe
lightgallery
Lightgallery is a powerful and flexible JavaScript library for creating image and video galleries. It offers a wide range of features including touch and mouse drag support, responsive design, and various plugins for additional functionalities. Compared to PhotoSwipe, Lightgallery provides more built-in features and customization options out of the box.
fancybox
Fancybox is a JavaScript library for displaying images, videos, and other content in a lightbox overlay. It is highly customizable and supports various content types, including HTML and AJAX. Fancybox is known for its ease of use and extensive documentation. While PhotoSwipe focuses on image galleries, Fancybox offers more versatility in terms of content types.
slick-carousel
Slick Carousel is a popular JavaScript library for creating responsive carousels and sliders. It supports various content types, touch and swipe gestures, and multiple customization options. Unlike PhotoSwipe, which is primarily for image galleries, Slick Carousel is more focused on creating sliders and carousels for a variety of content.
PhotoSwipe Repository
JavaScript image gallery for mobile and desktop.
Optionally, install via Bower: bower install photoswipe
.
Location of stuff
- Generated popup JS, CSS files, SVG & PNG sprites are in folder
dist/
. - Source files are in folder
src/
. - Website (examples & documentation) is in folder
website/
. - Documentation page itself is in
website/documentation.md
.
Plugins or extensions
Wrote a plugin for some CMS? Email me and I'll post link to it here.
Build
To compile PhotoSwipe by yourself, first of make sure that you have Node.js, Grunt.js, Ruby and Jekyll installed, then:
-
Copy repository
git clone https://github.com/dimsemenov/PhotoSwipe.git
-
Go inside PhotoSwipe folder that you fetched and install Node dependencies
cd PhotoSwipe && npm install
-
Now simply run grunt
to generate JS and CSS in folder dist
and site in folder _site/
.
grunt
Optionally:
- Run
grunt watch
to automatically rebuild script when you change files in src/
or in website/
. - If you don't have and don't want to install Jekyll, run
grunt nosite
to just build JS and CSS files related to popup in dist/
.
Using PhotoSwipe?
If you used PhotoSwipe in some interesting way, or on site of popular brand, I'd be very grateful if you shoot me a link to it.
License
Script is licensed under MIT license with one exception: Do not create a public WordPress plugin based on it, as I will develop it. If you need to use it for a public WordPress plugin right now, please ask me by email first. Thanks!
Attribution is not required, but much appreciated, especially if you're making product for developers.
About
The script was created by Code Computerlove, a digital agency in Manchester. In March 2014, it passed on development to Dmitry Semenov.