Skip to content

Events

Lifecycle callbacks are options on Glare.bind() and Glare.open(). Use them to sync UI, log failures, or cancel a close.

EventWhen it firesHandler receives
onInitInstance about to mount.(instance)
onActivateInstance mounted and on top of the stack.(instance)
beforeShowBefore the first slide is shown.(instance, current)
beforeLoadBefore a slide's content loads.(instance, current)
afterLoadContent ready.(instance, current)
afterShowSlide visible.(instance, current)
onErrorContent failed to load; current.error holds the reason. Without a handler, Glare logs a warning.(instance, current)
onUpdateAfter jumpTo changes the index.(instance, current)
beforeCloseAbout to close. Return false to cancel.(instance, current)
afterCloseFully closed and removed from the DOM.(instance, current)

Ask for confirmation before closing, and log load failures:

js
Glare.open(
  [
    { src: '/media/hero.jpg', caption: 'Hero' },
    { src: '/media/missing.jpg', caption: 'Broken link' },
  ],
  {
    afterShow(instance, current) {
      console.log('showing', current.src)
    },
    onError(instance, current) {
      console.error('could not load', current.src, current.error)
    },
    beforeClose() {
      return confirm('Close the lightbox?')
    },
  },
)

Released under the MIT License.