---
title: "jQuery Events"
date: 2018-09-09
author: "nK"
---

# jQuery Events

Events fire on the gallery element as `name.vpf` (and `name.vpf-uid-{uid}`) with the arguments `(event, vpInstance, ...args)`, and they bubble up to `document`. When you listen on `document`, check that `event.namespace` is `vpf`.

```
$( document ).on( 'init.vpf', function ( event, vp ) {
    if ( 'vpf' !== event.namespace ) {
        return;
    }
    console.log( vp.$item.attr( 'class' ) );
} );
```

## Gallery lifecycle

EventArguments after the instance`init`, `inited`none`initOptions`, `initEvents`, `destroyEvents`, `initLayout`, `initCustomColors`none`imagesLoaded`none`resized`none`destroy`none`addStyle``selector, styles, media, stylesList``removeStyle``selector, styles, stylesList``renderStyle``stylesString, stylesList, $style``addItems``$items, removeExisting, $newVP``removeItems``$items``startLoadingNewItems``url, ajaxData``loadedNewItems``$newVP, removeExisting, content``endLoadingNewItems`none## Layout libraries

EventArguments`beforeInitIsotope`, `initIsotope``options``destroyIsotope`none`beforeInitFjGallery`, `initFjGallery``options, additionalData``destroyFjGallery`none`beforeInitSwiper``options``initSwiper``options, instance``destroySwiper`none`swiperTouchStart`, `swiperTouchMove`, `swiperTouchEnd``swiper, event``beforeInitCustomScrollbar`, `initCustomScrollbar`, `destroyCustomScrollbar`none## Lightbox

These events also fire for third-party galleries opened through “Lightbox for WordPress Images”, with `null` in place of the gallery instance.

EventArguments`beforeInitFancybox``options, items, index``initFancybox``options, items, index, instance``beforeShowFancybox`, `afterShowFancybox`, `beforeCloseFancybox``event, instance, slide``beforeInitPhotoSwipe``options, items, index``initPhotoSwipe``options, items, index, instance``beforeChangePhotoSwipe`, `afterChangePhotoSwipe`, `beforeClosePhotoSwipe``instance``destroyPopupGallery`none## Extending the class

`extendClass.vpf` fires once on `document` with the gallery class, before any gallery is initialised, so an add-on can extend its prototype.