( function( $ ) { $(document).ready(function(){ // Auto-sizing imgSize = $('#slider img:first').height(); $('#slider').height(imgSize); // Create the animation zoom then fadeOut function zoomFade(element){ element.fadeOut(250); } //create animation for captions function captionMove(element) { element.transition({ opacity: 1, left: '50%' }); } // Determinate number of slides, if only one is counted, hide arrows nbSlides = $('#slider .slide').length; if (nbSlides <= 1) { $('.arrow-container').hide(); } // n is the current slide number nth-child(n) n = 1; // Init : show only first slide $('.slide').not('.slide:nth-child(' + n +')').hide(); $('.slide').not('.slide:nth-child(' + n +')').find('.slide-caption').css({ left: '60%' }); // On arrow click : $('.arrow-container').click(function(){ // Define if click is on "previous" or "next" direction = $(this).attr('id').split('-')[2]; // Define current, previous and next slide // Current currentSlide = $('.slide:nth-child(' + n +')'); currentCaption = $('.slide:nth-child(' + n +')').find('.slide-caption'); // Previous if (n === 1) { previousSlide = $('.slide:nth-child(' + nbSlides + ')'); previousCaption = $('.slide:nth-child(' + nbSlides + ')').find('.slide-caption'); } else { previousSlide = $('.slide:nth-child(' + (n-1) +')'); previousCaption = $('.slide:nth-child(' + (n-1) +')').find('.slide-caption'); } // Next if (n === nbSlides) { nextSlide = $('.slide:nth-child(1)'); nextCaption = $('.slide:nth-child(1)').find('.slide-caption'); } else { nextSlide = $('.slide:nth-child(' + (n+1) + ')'); nextCaption = $('.slide:nth-child(' + (n+1) + ')').find('.slide-caption'); } // Finally : ACTION !!! zoomFade(currentSlide); currentCaption.transition({ left: '60%', opacity: 0 }); if (direction === 'right') { nextSlide.fadeIn(); nextCaption.transition({ left: '50%', opacity: 1 }); if (n === nbSlides) { n = 1; } else { n = n+1; } } else { previousSlide.fadeIn(); previousCaption.transition({ left: '50%', opacity: 1 }); if (n === 1) { n = nbSlides; } else { n = n-1; } } }); }); } )( jQuery );