$(function(){ var isTransition = false; var speed = 1000; $('.carousel-nav-btns .btn-prev').on('click', function(e){ e.preventDefault(); goPrev(); }) ; $('.carousel-nav-btns .btn-next').on('click', function(e){ e.preventDefault(); goNext(); }) ; function goPrev() { if ( isTransition ) return; var prevSlide = $('.home-carousel .slides .slide.active').prev(); if ( !prevSlide[0] ) { prevSlide = $('.home-carousel .slides .slide:last-child'); } showSlide(prevSlide); } function goNext() { if ( isTransition ) return; var nextSlide = $('.home-carousel .slides .slide.active').next(); if ( !nextSlide[0] ) { nextSlide = $('.home-carousel .slides .slide:first-child'); } showSlide(nextSlide); } function showSlide(slide) { isTransition = true; $('.home-carousel .slides .slide.active').addClass('prev').siblings().removeClass('prev'); slide.addClass('active').siblings().removeClass('active'); var animTop = Math.abs(parseInt($('.home-carousel .carousel-item .bg').css('top'))); $('.back', slide).css({'top': animTop, 'opacity':0}).stop().animate({'top':0, 'opacity':1}, speed, 'easeOutQuint', function(){ isTransition = false; }); $('.section-title', slide).css({'top': animTop * .5, 'opacity':0}).stop().delay(300).animate({'top':0, 'opacity':1}, speed, 'easeOutQuint'); $('.section-desc', slide).css({'top': animTop * .5, 'opacity':0}).stop().delay(400).animate({'top':0, 'opacity':1}, speed, 'easeOutQuint'); $('.btn-more', slide).css({'top': animTop * .5, 'opacity':0}).stop().delay(500).animate({'top':0, 'opacity':1}, speed, 'easeOutQuint'); $('.home-carousel .indices a[href="#' + slide.attr('id') + '"]').closest('li').addClass('active').siblings().removeClass('active'); } $('.home-carousel .indices a').on('click', function(e){ e.preventDefault(); var nextSlide = $('.home-carousel .slides .slide' + $(this).attr('href')); showSlide(nextSlide); }); var mc = new Hammer($('.home-carousel')[0]); mc.get('swipe').set({ direction: Hammer.DIRECTION_HORIZONTAL }); mc.on("swipeleft swiperight", function(e) { if ( Math.abs(e.deltaX) < 30) return; if ( e.type == "swiperight") { goPrev(); } else { goNext(); } }); });