loryjs / lory

☀ Touch enabled minimalistic slider written in vanilla JavaScript.
http://loryjs.github.io/lory/
MIT License
2.28k stars 243 forks source link

Using the API methods in Vanilla JS #771

Open CedricEggenspiller opened 5 years ago

CedricEggenspiller commented 5 years ago

Hi, thanks for this plugin. I'd like to make the slideshow run automatically. I wanted to use the .next() method with a timeout but I'm unable to make the equivalent of JQuery data() (like in your example : $elements.data().lory.next();) in vanilla JS. Any idea? And maybe that could be a future improvement to have an auto slideshow option.

Thank you !

Cédric

longdoan7421 commented 4 years ago

You could use something like this:

var el = document.getElementById('#slider');
var slider = lory(el, options);
var timeout;
var triggerAutoSlide = function () {
    timeout = setTimeout(function () {
         slider.next();
    }, 300 + 3000); // transition time + delay time
}
triggerAutoSlide(); // trigger after init
el.addEventListener('after.lory.slide', function () {
    clearTimeout(timeout);
    triggerAutoSlide();
});
CedricEggenspiller commented 4 years ago

Oh, great, thank you !

Le 20 mars 2020 à 03:39, Long Đoàn notifications@github.com a écrit :

You could use something like this:

var el = document.getElementById('#slider'); var slider = lory(el, options); var timeout; var triggerAutoSlide = function () { timeout = setTimeout(function () { slider.next(); }, 300 + 3000); // transition time + delay time } triggerAutoSlide(); // trigger after init el.addEventListener('after.lory.slide', function () { clearTimeout(timeout); triggerAutoSlide(); }); — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/loryjs/lory/issues/771#issuecomment-601501832, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANA2OCYGO5ITPYM2ZWZIZY3RILJP7ANCNFSM4JSWRZLA.

Cédric Eggenspiller