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));
}