LayerSlider is built on standard web technologies like HTML, CSS, and Javascript, and offers a way to extend the capabilities of the plugin through the LayerSlider API. Please note, this requires programming skills and web development experience, thus we cannot recommend it to users without the necessary knowledge.

Event reference

Event callbacks is a way to receive notifications and run custom code when certain actions occur in sliders. The following events can be used under the Event Callbacks tab of the Slider Builder.

Init Events Description
sliderWillLoad Fires as soon as a LayerSlider instance has been created, but before processing any user data or rendering the UI. This gives you a chance to perform any task before LayerSlider tries to parse the markup and user settings. Since this event occurs in mid-initialization, you must bind this event on the target element before calling .layerSlider().
sliderDidLoad Fires when a LayerSlider instance is fully initialized and its UI elements become accessible for DOM manipulation. You should bind this event on the target element before calling .layerSlider() to avoid timing issues.
Resize Events Description
sliderWillResize Fires before resizing and rendering sliders due to a viewport/orientation etc. change. Keep in mind that running slow code in this event can lead to performance issues, as it is called subsequently in multiple times.
sliderDidResize Fires after sliders have been resized and rendered due to a viewport/orientation etc. change. Keep in mind that running slow code in this event can lead to performance issues, as it is called subsequently in multiple times.
Slideshow Events Description
slideshowStateDidChange A changed slideshow state can occur for various reasons, such as starting media playback, hovering over the slider, manually pausing the slideshow, etc. This event fires at any state change. Since there are multiple states, it's not guaranteed that there is an actual change in playing/pausing the slideshow. Slideshow states can be retrieved from the Event Data object passed to the callback handler.
slideshowDidResume This event fires when the slideshow resumes from a paused state. Please note that slide timers and layer transitions are not bound to the slideshow directly. Depending on the pauseLayers option, the slide's animation timeline can continue its progress towards the end of the slide and wait for slide change until the slideshow resumes from its paused state. You can examine the passed Event Data object to identify which settings is applied.
slideshowDidPause Fires when the slideshow pauses from a playing state. As mentioned in the previous event, the pauseLayers option decides which (if any) animations can continue playing in the background. The slideshow paused state only guarantees the prevention of changing slides. You can examine the passed Event Data object to identify which settings is applied.
Slide Change Events Description
slideChangeWillStart This event signals whenever the slider wants to change slides, and is your last chance to divert or intervene in any way. The proposed slide indexes and other relevant information is in the passed Event Data object.

Return false to prevent slide change, or return an integer to switch to that slide instead of the proposed one.
slideChangeDidStart This is the last notification before the slider commences a slide change. At this point you can no longer divert or intervene, its only purpose is letting you know the next slide index and other relevant data in advance.
slideChangeWillComplete Fires before completing the slide change. Since at this point the slide change is still in progress, the current slide's index is still pointing to the previous slide. Please note, layers animation may occur earlier in execution depending on the timeShift option. See the Slide Timeline Events section if you're looking for an event like that.
slideChangeDidComplete Fires after a slide change has completed and the slide indexes have been updated. Please note, layers animation may occur earlier in execution depending on the timeShift option. See the Slide Timeline Events section if you're looking for an event like that.
Slide Timeline Events Description
slideTimelineDidCreate Fires when the current slide's animation timeline (e.g layer transitions on the slide) has been created. This event lets you know when the GSAP timeline object becomes accessible for interfacing.
slideTimelineDidUpdate Fires rapidly (at each frame) throughout the entire slide while the animation timeline (e.g. your layers on the slide) is playing. This includes reverse playback as well.
slideTimelineDidStart Fires when the current slide's animation timeline (e.g. your layers) has started. This event signals the exact time in execution when the first (earlier) layer becomes visible and transitions are taking place.
slideTimelineDidComplete Fires when the current slide's animation timeline has completed (e.g. layer transitions) and the slider is ready to change slides. However, changing slides is not yet guaranteed at this point, as it depends on slideshow states and other factors.

This event only concerns transitions occurring on the slide, thus it is possible to divert the slider or intervene in any way before changing slides. The proposed slide indexes and other relevant information is in the passed Event Data object.
slideTimelineDidReverseComplete Fires when all animations on a reversed slide have reached their starting point and the slide is ready to be played from the beginning.
Popup Events Description
popupWillOpen Fires when the Popup starts its opening transition and becomes visible.
popupDidOpen Fires when the Popup completed its opening transition.
popupWillClose Fires when the Popup stars its closing transition.
popupDidClose Fires when the Popup completed its closing transition and became hidden.
Destroy Events Description
sliderDidDestroy Due to technical reasons, destroying a slider may not happen instantaneously. This event lets you know when the slider destructor has finished and it is safe to remove the slider from DOM after calling the destroy API method.
sliderDidRemove This event is fired as the last step when destroying a slider and the second parameter true was passed in the destroy API method indicating to remove the slider.

Event Data object

Most event handler functions will have the same 2 pre-defined variables passed. Those are the jQuery Event object and our custom slider data object. You can name these variables by your choice, but we will refer to them as event and slider in our examples.

Every slider data object will contain the same properties, regardless of the used event. However, it's possible that some values are not yet set depending on the current point of execution. The data object contains the most relevant information, but we've also included the entire LayerSlider instance data source, which you can use to access or modify properties on the fly, as well as to add new methods to implement new features.

We encourage everyone to use the browser developer tools and examine the returned data by using console.log() to see potentially undocumented data. Here is an example that you can paste into your browser's JavaScript console. Please make sure to use the right selection when targeting the slider container element on which the LayerSlider instance was created.

1
2
var data = jQuery('#slider').layerSlider('eventData');
console.log( data );


Please note, the slider. prefix in every property name refers to the passed variable to callback functions, which can be named differently.
Slider Properties Type Value
slider.data Object The complete data source object of the current LayerSlider instance. Since this is a reference, you can access and modify any part of the object. You can event add new methods to implement new features this way.
slider.userData Object The parsed (e.g. defaults included) slider options which have been set by the user in the init code.
slider.target DOMNode The slider container element, on which LayerSlider was initialized.
slider.state Object The slider states object, which indicates whether the slider is preloading images, changing or animating slides etc.
slider.isBusy Boolean Returns a boolean value indicating whether the slider is busy to complete background tasks (see slider.state).
slider.api() Function The shortcut to execute API commands. Example: slider.api('next');
First (Starting) Slide Properties Type Value
slider.slides.first.index Integer The index of the first (starting) slide. The count starts from 1 instead of zero.
slider.slides.first.deeplink String Deeplink of the first (starting) slide (if any).
Previous Slide Properties Type Value
slider.slides.prev.index Integer The index of the previous slide. The count starts from 1 instead of zero. Please note, this value is updated after the slideChangeDidComplete event.
slider.slides.prev.deeplink String Deeplink of the previous slide (if any).
Current Slide Properties Type Value
slider.slides.current.index Integer The index of the current slide. The count starts from 1 instead of zero. Please note, this value is updated after the slideChangeDidComplete event.
slider.slides.current.deeplink String Deeplink of the current slide (if any).
slider.slides.current.layersIn jQery Collection A jQuery collection of DOM nodes, which contains layers appearing on the current slide, including static layers.
slider.slides.current.layersOut jQuery Collection A jQuery collection of DOM nodes, which contains layers leaving on the current slide. This includes static layers, since they aren't bound to their origin slide.
slider.slides.current.timeline GSAP TimelineMax The current slide's animation timeline, which you use to easily manipulate animations. Slow them down, repeat them, reverse them. You can do GreenSock functions to easily achieve surprising effects.
Next Slide Properties Type Value
slider.slides.next.index Integer The index of the proposed next slide. The count starts from 1 instead of zero. The next slide can change at any time by a user action or API commands.
slider.slides.next.deeplink String Deeplink of the next slide (if any).
slider.slides.next.layersIn jQuery Collection The same as slider.slides.current.layersIn for the proposed next slide. The next slide can change at any time by user action or via API commands.
slider.slides.next.layersOut jQuery Collection The same as slider.slides.current.layersOut for the proposed next slide. The next slide can change at any time by user action or via API commands.
Miscellaneous Slide Properties Type Value
slider.slides.count Integer The number of slides in a slider.
slider.slideChangeTimeline GSAP TimelineMax The slide transition animation timeline, which is used when changing slides. You can use GreenSock functions to easily manipulate the transition.
Slideshow Properties Type Value
slider.slideshow.state Object An object of slideshow states, which determines whether the slider is paused or not. There are several states such as media playback, hovering over the slider, manually pausing the slideshow, etc.
slider.slideshow.sequence Array An array containing slide indexes, which indicated the pre-determined order of slides. This takes into account of random slideshows, and provides a reliable value without user action.
slider.slideshow.direction String 'prev' or 'next' indicating whether the slideshow is playing forwards of backward depending on the twoWaySlideshow option.
slider.slideshow.isPaused Boolean Boolean indicating if the slideshow is paused at the time of execution. Depending on the pauseLayers setting, the slide animation timeline may still continue its progress towards the end of the slide. This means that layer transitions and progress timers may not be interrupted, but the slider will not commence to the next slide until resuming the slideshow.
Cycles Properties Type Value
slider.cycles.max Integer The number of cycles that the user set.
slider.cycles.current Integer The number of cycles that the slider has performed at the time of execution.

API methods

The below API methods can be used to control sliders externally, modify their behavior, or wire them up with 3rd party solutions. By using the right combinations of API events and commands, you can implement new features or extended the capabilities of the plugin with custom code. Please note, API events are exposed to the API commands in the same way as anything else. Be aware that most API methods will trigger the appropriate API events as well.

Method name Description Example
(integer) Initiate a slide change to the specified slide number. The count starts from 1. The example on the right side shows how to switch to the third slide. $('#slider').layerSlider(3);
nextSlide or
next
Skips to the next slide in the sequence. $('#slider').layerSlider('next');
previousSlide or
prev
Changes to the previous slide. $('#slider').layerSlider('prev');
replaySlide or
replay
Restarts the slide, replays all layer transitions from the beginning. $('#slider').layerSlider('replay');
reverseSlide or
reverse
Play the slide and all transitions backwards, then pause at the beginning of the slide. Pass true as a second parameter to continue replaying the slider normally afterward. $('#slider').layerSlider('reverse', true);
resetSlide Immediately sets the current slide back to its starting state and pauses it. $('#slider').layerSlider('resetSlide');
stopSlideshow or
stop
Stops the slideshow. Depending on the pauseLayers setting, the slide animation timeline may still continue its progress towards the end of slide. This means that layer transitions and progress timers may not be interrupted, but the slider will not commence to the next slide until resuming the slideshow. $('#slider').layerSlider('stop');
startSlideshow or
start
Resumes the slideshow and re-enables the slider to change slides when reaching the end of animation timeline. Since transitions may occur even in a paused state depending on the pauseLayers setting, it possible that the timeline has already reached its end point when calling this command. $('#slider').layerSlider('start');
pauseSlider or
pause
Stops the slider by freezing every animation taking place at the time of execution, including slide transitions when changing slides. $('#slider').layerSlider('pause');
resumeSlider or
resume
Resumes the slider and continues playing frozen animations. $('#slider').layerSlider('resume');
toggleSlider or
toggle
Toggles between pauseSlider and resumeSlider by respecting the current state. $('#slider').layerSlider('toggle');
openPopup Opens initialized Popups waiting in the background to be launched. $('#slider').layerSlider('openPopup');
closePopup Closes the Popup. $('#slider').layerSlider('closePopup');
data Returns the entire data object that the slider uses. var data = $('#slider').layerSlider('data');
eventData Returns the Event Data object filled with the relevant values at the time of execution. var data = $('#slider').layerSlider('eventData');
userInitOptions Returns the slider options provided by the user in the init code. var data = $('#slider').layerSlider('userInitOptions');
defaultInitOptions Returns the full list of the default slider options. var data = $('#slider').layerSlider('defaultInitOptions');
sliderInitOptions Returns the parsed slider options (extended by user data) used to initialize the slider. var data = $('#slider').layerSlider('sliderInitOptions');
originalMarkup Returns the original HTML markup that the slider was initialized on. var data = $('#slider').layerSlider('originalMarkup');
redrawSlider or
redraw
Recalculates the slider styles and repaints the slider. Useful when you want to manually trigger responsive calculations to update the slider UI. $('#slider').layerSlider('redraw');
destroy or
kill
Destroys the LayerSlider instance by canceling timers, removing events, freeing up allocated memory. Passing a second parameter true will also remove the slider element from the DOM.

Due to technical reasons, destroying a slider may not happen instantaneously. See the sliderDidDestroy and sliderDidRemove events for more information.
$('#slider').layerSlider('destroy', true);

Examples

  • Switch slides with custom controls:

    1
    <a href="javascript:void(0);" onclick="$('#slider').layerSlider(2);">Change to slide 2</a>
  • Combining callbacks and API methods:

    The following example will bring up an alert message after every slide change with the current slide number. It can be used with the slideChangeDidComplete event callback.

    1
    2
    3
    function(event, slider) {
        alert('The current slide is: ' + slider.slides.current.index);
    }
© WebshopWorks - Professional PrestaShop Addons