javascripteventsslidersplidejs

Splide.js get slide id on moved event


In slide.js there are several events which have a return value.

I want to read the return value of the moved event (newIndex, prevIndex, destIndex) and print it in the console for now. https://splidejs.com/guides/events/#moved

I have this code:

splide1.on( 'moved', function () {
    console.log(`this.newIndex`);
} );

But when I slide the slider in console only an "undefined" keyword appears.


Solution

  • The event parameters are not attributes of this but parameters to the callback function:

    splide1.on( 'moved', function (newIndex, prevIndex, destIndex) {
        console.log(`newIndex`);
    } );