Upgrading GLightbox from V3

Everything you need to know before upgrading to the latest version


⚠️

There are many breaking changes, make sure to test your code locally. We have created several guides to help you get started with this new update.

Library options

Numerous options have been either removed or relocated. V4 was designed to embrace modularity and extensibility through plugins. Instead of being overwhelmed with an array of options, each plugin now comes with its own dedicated configuration, allowing for a more organized and customizable approach. To see the available options check the GLightbox options documentation and also the Plugins documentation

Removed options

OptionReason
selectorNow the library uses the data attribute data-glightbox, to create multiple galleries you can assign a name data-glightbox="mygallery"
widthEach plugin can define options to control width if required
heightEach plugin can define options to control height if required
videosWidthConfiguration provided by the video plugin
autoplayVideosConfiguration provided by the video plugin
autofocusVideosConfiguration provided by the video plugin
draggableConfiguration provided by the drag plugin
dragToleranceXConfiguration provided by the drag plugin
dragToleranceYConfiguration provided by the drag plugin
dragAutoSnapConfiguration provided by the drag plugin
zoomableIt will be controlled by plugins if available
descPositionIt will be controlled by theme plugins
plyrPlyr no longer included
closeButtonNot particularly useful and should be controlled by theme plugins
cssEfectsThis is now controlled by theme plugins

Moved options

OptionReason
elementsRenamed to items
skinRenamed to theme and moved to the appearance configuration
openEffectMoved to the appearance configuration
closeEffectMoved to the appearance configuration
slideEffectMoved to the appearance configuration
moreTextMoved to the appearance configuration
moreLengthMoved to the appearance configuration
lightboxHTMLMoved to the appearance configuration
slideHTMLMoved to the appearance configuration

Removed Methods

The majority of methods remain the same, only one method was removed.

OptionReason
openAtThe open method can do exactly the same

Browsers support

Version V4 discontinues support for IE11, concentrating solely on modern browsers. This intentional focus has allowed us to streamline the codebase significantly, resulting in a notable reduction in size and complexity.

HTML Changes

⚠️

In V3 the data attribute data-glightbox was used to provide information like title, description and many more values. If you were using the attribute like this, make sure to update your code.

One of the main changes is that now you don’t need to specify a selector or use the glightbox class, now the library uses the data-glightbox attribute

<!-- Previous HTML -->
<a href="large.jpg" class="glightbox">
  <img src="small.jpg" alt="image" />
</a>

<!-- New HTML -->
<a href="large.jpg" data-glightbox>
  <img src="small.jpg" alt="image" />
</a>

By default, the library automatically groups all elements with the data-lightbox attribute to form a gallery. If you wish to disable this behavior and display only one item at a time, you can utilize the autoGallery option when initializing GLightbox. This was not posible in older versions.

const lightbox = new GLightbox({
  autoGallery: false
});

Creating multiple galleries

Previously, to group elements into a gallery, it was necessary to utilize the data-gallery attribute, Now you can achieve the same functionality simply by assigning a value to the data-glightbox attribute

<!-- Previous HTML -->
<a href="large.jpg" class="glightbox" data-gallery="mygallery">
  <img src="small.jpg" alt="image" />
</a>

<!-- New HTML -->
<a href="large.jpg" data-glightbox="mygallery">
  <img src="small.jpg" alt="image" />
</a>

In development…