splide icon indicating copy to clipboard operation
splide copied to clipboard

how to run functions on splide events without "var splide = new Splide" ?

Open juliopimentel opened this issue 5 years ago • 2 comments

Hi again, I`m kind of a newbie to js and I need to trigger one of the Api without declaraing a variable.

According to the splide documentaion this is how to "do something" after the slide moves:

var splide = new Splide( '#splide' ).mount(); splide.on( 'moved', function() { // do something } );

But how can I call that "event" withouth declaring the "splide" variable, just calling the .splide element, something like:

$("#MySplide").('moved', function() { // do something } );

I hope I have explained myself well and thanks in advance for the help! (:

juliopimentel avatar Dec 22 '20 18:12 juliopimentel

Pretty close, just needed the .on before .('moved') in the second example!

new Splide( '#splide' ).mount().on( 'moved', function() {
// do something
} );

You can essentially collapse the variable and perform it all on "one line" (note: not really 1 line)

ghost avatar Jan 18 '21 05:01 ghost

Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.

NaotoshiFujita avatar Oct 09 '21 14:10 NaotoshiFujita