HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rentman.komma.pro/wwwroot/js/introSlider.js
/**
 * Created by Pascal on 30/11/16.
 */

$(function () {
    var index = 0;
    var maxIndex = 0;

    $('.intro-row .image-container .nav ul li').each(function () {
        if(maxIndex < $(this).data('button')) maxIndex = $(this).data('button');
    });

    $('.intro-row .image-container .nav ul li').click(function () {
        index = $(this).data('button');
        setNewActive(index);
        clearInterval(loopAnimation);
        loopAnimation = setInterval(nextSlider, 4000);
    });

    loopAnimation = setInterval(nextSlider, 4000);

    $('.intro-row .image-container').swipe({
        swipeLeft: function () {
            nextSlider();
        },
        swipeRight: function () {
            previousSlider();
        }
    });

    document.onkeydown = function (e) {
        if ((e.keyCode || e.which) == 37)
        {
            nextSlider();
        }
        if ((e.keyCode || e.which) == 39)
        {
            previousSlider();
        }
    }




    function nextSlider() {
        index++;
        if(maxIndex < index) index = 0;
        setNewActive(index);
        clearInterval(loopAnimation);
        loopAnimation = setInterval(nextSlider, 4000);
    }

    function previousSlider() {
        index--;
        if(index < 0) index = maxIndex;
        setNewActive(index);
        clearInterval(loopAnimation);
        loopAnimation = setInterval(nextSlider, 4000);
    }

});


function setNewActive(i) {
    $('.intro-row .image-container .nav ul li.active').removeClass('active');
    $('.intro-row .image-container .label span').removeClass('active');
    $('.intro-row .image-container span').removeClass('active');

    $('.intro-row .image-container .nav ul li[data-button="' + i + '"]').addClass('active');
    $('.intro-row .image-container .label span[data-label="' + i + '"]').addClass('active');
    $('.intro-row .image-container span[data-image="' + i + '"]').addClass('active');
}