Version 2.0.0 was a complete rewrite in modern ES6 JavaScript that no longer needs jQuery. The public surface kept its shape — the options, the event names and the methods — so on most sites only the line that creates the lightbox changes.
The 1.x series was a jQuery plugin through and through. Moving to 2.x removes that dependency from pages that only loaded jQuery for the lightbox, and it opens the door to ES modules and bundlers.
// 1.x: jQuery plugin
var lightbox = $('.gallery a').simpleLightbox({ loop: false });
// 2.x: standalone build
var lightbox = new SimpleLightbox('.gallery a', { loop: false });
// 2.x: jQuery build, same call as before
var lightbox = $('.gallery a').simpleLightbox({ loop: false });
If jQuery stays on the page and you do not want to touch the start-up code, load simple-lightbox.jquery.min.js instead of the standalone file. The old call keeps working unchanged.
For bundlers there are two entry points: import SimpleLightbox from "simplelightbox" for the module with Babel transformation, and "simplelightbox/dist/simple-lightbox.esm" for the plain ES module.
Event names are unchanged: show.simplelightbox, closed.simplelightbox and the rest. With the standalone build you listen on the object that new SimpleLightbox() returns:
var lightbox = new SimpleLightbox('.gallery a');
lightbox.on('shown.simplelightbox', function () {
// the image is visible now
});
open, close, next, prev, destroy and refresh are available as before. One detail is easy to miss: refresh() only works when the lightbox was created with a selector string, because it rebuilds itself from that selector.
Existing options kept their meaning. These were added during the 2.x series and are worth a look while you migrate:
| Version | Option | What it does |
|---|---|---|
| 2.1.0 | rel, rtl | Group images by the rel attribute; right-to-left layout |
| 2.4.0 | fixedClass | Fixed elements get right padding when the page scrollbar disappears |
| 2.5.0 | fadeSpeed | Duration of fades, also used for captions |
| 2.6.0 | uniqueImages, focus | Skip duplicate links; focus the lightbox for keyboard and tab control |
| 2.9.0 | scrollZoom, scrollZoomFactor | Zoom with the mouse wheel |
| 2.11.0 | captionClass | Now accepts several classes separated by spaces or commas |
| 2.12.0 | download | Text for a download link below the image |
The standalone build targets current browsers. Sites that still have to serve Internet Explorer 11 can use simple-lightbox.legacy.min.js, available since 2.4.1. Remove any IE-specific workarounds you added around the 1.x plugin — the legacy build takes care of that.
$(…).simpleLightbox() to new SimpleLightbox(), or load the jQuery build.refresh().The gallery below runs on 2.x with two of the newer options, fadeSpeed and scrollZoom: