nir9 / itemslide

JavaScript Touch Carousel Library with Zero Dependencies
https://itemslide.org
MIT License
647 stars 85 forks source link

Auto Sliding #77

Closed chinkan closed 4 years ago

chinkan commented 7 years ago

Would it be possible to auto sliding by a interval?

nir9 commented 7 years ago

i guess i can add that. you can implement it yourself quite easily with setInterval,

studiolxv commented 5 years ago

This will advance every 4 seconds and return to the first slide after the last slide has been displayed for the delayTime amount. Hope it helps someone.

`var carousel;

$(document).ready(function() {

carousel = $("#itemslide ul");

carousel.itemslide({
    one_item: true, //Set this for proper full screen navigation
    disable_scroll: true,
    parent_width: true,
    duration: 1500
}); //initialize itemslide

$(window).resize(function() {
    carousel.reload();

}); //Recalculate width and center positions and sizes when window is resized

var delayTime = 4000;

var SetTimer = setInterval(function() {
    carousel.next();
}, delayTime);

function resetTimer() {
    clearInterval(SetTimer);
    SetTimer = setInterval(function() {
        carousel.next();
    }, delayTime);
}

// Buttons
// 
$("#next").click(function() {
    carousel.next();
    resetTimer();
});

$("#previous").click(function() {
    carousel.previous();
    resetTimer();
});

carousel.on('pan', function(event) {
    resetTimer();
});

function addClass() {
    i = 1;
    $('#itemslide ul li').each(function(i) {
        $(this).addClass('slide-' + i);
    });
}
addClass();

carousel.on('changeActiveIndex', function(e) {
    var slideCount = $('#itemslide ul li').length;
    var currentSlide = carousel.getActiveIndex();
    var lastSlide = slideCount - 1;

    if (currentSlide == lastSlide) {
        setTimeout(function() {
            carousel.gotoSlide(0);
        }, delayTime);

    }

});

});`

nir9 commented 4 years ago

Due to the fact this feature can be implemented easily without support from the lib, I am closing this issue