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/PDeckers/opelkapitan.nl/wwwroot/js/imageSlider.js
/**
 * Created by Pascal on 30/11/16.
 */

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

    $('.image-slider .images .image').each(function () {
        if(maxIndex < $(this).data('image')) maxIndex = $(this).data('image');
    });

    $('.image-slider .controllers .control').click(function () {
        if($(this).hasClass('right')){
            nextSlider();
        }
        else{
            previousSlider();
        }

        setNewActive(index);
        clearInterval(loopAnimation);
        loopAnimation = setInterval(nextSlider, 4000);
    });

    loopAnimation = setInterval(nextSlider, 4000);

    $('.image-slider').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();
        }
    }

    $(window).resize(
        $.throttle( 250, resizeSlider )
    );
    resizeSlider();



    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) {
    $('.image-slider .images .active').removeClass('active');
    $('.image-slider .controllers .control').data('button', i);
    $('.image-slider .images .image[data-image="' + i + '"]').addClass('active');
}

function resizeSlider() {
    var slider = $('.image-slider');
    slider.height(slider.width()/800*533);
}