About application programming interfaces (APIs)

An API is a way to control an application, or get some info about the data which the application is working with. This is a way to two separate application can work together. LayerSlider has an API too, you can control the slider from outside of the application.

API methods

Using the API

To run one of the above API command, you have to call the LayerSlider jQuery method on the slider element and pass the command as a parameter. WordPress uses IDs on each slider with the word "layerslider_" and the number of the selected slider.

Example: jQuery('#layerslider_1').layerSlider(2);

This will switch to the second slide. If you want to use this with a link, you can use the following code:

<a href="javascript:void(0);" onclick="$('#layerslider').layerSlider(2);">to slide 2</a>

Working with LayerSlider data

The LayerSlider data object is a huge collection with all the information you need. We don't have enough space here to list all of the properties you can work with, you have to check them manually. Here are the most important ones:

Callback functions and LayerSlider API

When you request the LayerSlider data object with its API call, you will have the information for that exact moment. When LayerSlider working along, these informations may change or will be outdated. You probably want to use this information in an exact moment, when something just happened, so you have to use the LayerSlider API and the callback events at the same time. To do that, you can use a custom named variable in the callback function header section which will be filled with the data object of LayerSlider. Here is an example of using both with the cbAnimStart event:

function(data) {
	alert('The next slide is: ' + data['nextLayerIndex']);

A more complex example

Here is a more complex example which show which things you can do with our API. This example implement a custom navigation area for a LayerSlider slider.

You can find this example here.