I'm making a slider, and I need it to start again when I see the images, but I can not. Could someone help?
JS
$(function(){
// Buttons Hover Effect
buttonsHover();
function buttonsHover(){
var buttons = $('.buttons');
var container = $('#container');
container.hover(function(){
buttons.fadeIn();
}, function(){
buttons.fadeOut();
});
}
/* ----------------------------------------------------------------------------------------------------------------------------------------- */
// slide
var numImages = 0;
var currentImage = 1;
var totalWidth = 0;
var galleryUlLi = $('.gallery-ul li');
var galleryUl = $('.gallery-ul');
var leftButton = $('.left_b');
var rightButton = $('.right_b');
var interval = 0;
hideButtons();
loop();
// images_container li class with a function to add values for each numImages and totalWidth variables
galleryUlLi.each(function(){
numImages++;
totalWidth += 1200;
});
// images_container class with the css width value of the images
galleryUl.css('width', totalWidth + 'px');
// Right button click function
rightButton.click(function(){
moveLeft();
hideButtons();
clearLoop();
loop();
});
// Left button click function
leftButton.click(function(){
moveRight();
hideButtons();
clearLoop();
loop();
});
// Move Left function
function moveLeft(){
if(currentImage < numImages){
galleryUl.animate({'margin-left': '-=1200px'}, 1000);
currentImage++;
hideButtons();
}
}
// Move Right function
function moveRight(){
if(currentImage > 1){
galleryUl.animate({'margin-left': '+=1200px'}, 1000);
currentImage--;
hideButtons();
}
}
// function hide buttons
function hideButtons(){
if(currentImage === 1){
leftButton.hide();
}
else{
leftButton.show();
}
if(currentImage === numImages){
rightButton.hide();
}
else{
rightButton.show();
}
}
function loop(){
interval = setInterval(moveLeft, 3000);
}
function clearLoop(){
clearInterval(interval);
}
}); // End of main function