How to make a slider refresh with JavaScript?

时间:2019-04-17 02:50:35

标签: javascript html

Using the JavaScript code I have, the slider goes through the slides perfectly fine the first time. Although when the slider goes to the very first slide to start through again, the slide gets stuck.

I think it has something to do with my if/else statement, but I am honestly at a loss.

I have tried multiple different versions of this code, but I ultimately come back to the same problem.

var interval = setInterval(handleNext, 6000);

function handleNext() {

    var $radios = $('input[class*="slide-radio"]');
    var $activeRadio = $('input[class*="slide-radio"]:checked');

    var currentIndex = $activeRadio.index();
    var radiosLength = $radios.length;

    $radios
        .attr('checked', false);

    if (currentIndex >= radiosLength - 1) {

        $radios
            .first()
            .attr('checked', true);
    }
    else {
        $activeRadio
            .next('input[class*="slide-radio"]')
            .attr('checked', true);
    }
}

I am trying to make the slides continous, where all the slides flow correctly, without having to refresh the page.

I appreciate any help!

0 个答案:

没有答案
相关问题