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/jacques-hein.komma.pro/wwwroot/js/slider.js
/**
 * Created by Pascal on 24/01/17.
 */

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

    $('.slider .nav-items ul li').each(function () {
        if(maxIndex < $(this).data('nav')) maxIndex = $(this).data('nav');
    });

    $('.slider .nav-items ul li').click(function () {
        index = $(this).data('nav');
        setNewActive(index);
    });

    $('.slider .arrows .left').click(function () {
        previousSlider();
    });

    $('.slider .arrows .right').click(function () {
        nextSlider();
    });


    $('.slider').swipe({
        swipeLeft: function () {
            nextSlider();
        },
        swipeRight: function () {
            previousSlider();
        }
    });

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


    function nextSlider() {
        index++;
        console.log(index);
        if(index > maxIndex) index = 0;
        setNewActive(index);
    }

    function previousSlider() {
        index--;
        if(index < 0) index = maxIndex;
        setNewActive(index);
    }

    setNewActive(index);

    $(window).resize(
        function () {
            setNewActive(index);
        }
    );

});


function setNewActive(i) {
    $('.slider .nav-items ul li.active').removeClass('active');
    $('.slider .items .item').removeClass('active');

    $('.slider .nav-items ul li[data-nav="' + i + '"]').addClass('active');

    var sliderItem = $('.slider .items .item[data-item="' + i + '"]');
    sliderItem.addClass('active');

    $('.slider').height((sliderItem.height() + 100));
}