Advertisement
Dimalolzet

Aquamarin initCarousel

May 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. initCarousel = function() {
  3.     'use strict';
  4.     var $titlePrimary, $titleSecondary;
  5.     $titlePrimary = $('.intro__title_primary');
  6.     $titleSecondary = $('.intro__title_secondary');
  7.     return $('.carousel-block').each(function() {
  8.         var $carousel, arrows, center, count, speed, swipe;
  9.         $carousel = $(this).find('.carousel');
  10.         count = $carousel.data('count' != null ? 'count' : 1);
  11.         arrows = $carousel.data('arrows' != null ? 'arrows' : false);
  12.         center = $carousel.data('center' != null ? 'center' : false);
  13.         speed = $carousel.data('speed' != null ? 'speed' : 300);
  14.         swipe = windowWidth <= 992;
  15.         $carousel.slick({
  16.             slidesToShow: count,
  17.             slidesToScroll: 1,
  18.             swipe: swipe,
  19.             pauseOnHover: false,
  20.             autoplay: true,
  21.             autoplaySpeed: 5000,
  22.             speed: speed,
  23.             arrows: arrows,
  24.             centerMode: center,
  25.             prevArrow: $(this).find('.carousel__button_prev'),
  26.             nextArrow: $(this).find('.carousel__button_next'),
  27.             responsive: [{
  28.                 breakpoint: 992,
  29.                 settings: {
  30.                     slidesToShow: 1,
  31.                     centerMode: false
  32.                 }
  33.             }]
  34.         });
  35.         if ($carousel.hasClass('intro-carousel')) {
  36.             $carousel.on('beforeChange', function(event, slick, currentSlide, nextSlide) {
  37.                 var $activeSlide;
  38.                 $activeSlide = $(slick.$slides[nextSlide]);
  39.                 $titlePrimary.text($activeSlide.data('title'));
  40.                 return $titleSecondary.text($activeSlide.data('caption'));
  41.             });
  42.             return $carousel.slick('slickGoTo', 0);
  43.         }
  44.     });
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement