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