Advertisement
Mihalytch

jcarousel

Nov 26th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('.jcarousel').each(function() {
  2.     var $carousel = $(this);
  3.  
  4.     $carousel
  5.         .on('jcarousel:reload jcarousel:create', function () {
  6.             var width = $carousel.innerWidth();
  7.             $carousel.jcarousel('items').css('width', width + 'px');
  8.         })
  9.         .jcarousel({
  10.             list: '.jcarousel__slider',
  11.             items: '.jcarousel__slide',
  12.             wrap: 'circular'
  13.         });
  14.        
  15.     if ($carousel.data('prev')) {
  16.         var $prev = $('#' + $carousel.data('prev') );
  17.        
  18.         $prev.jcarouselControl({
  19.             target: '-=1',
  20.             carousel: $carousel
  21.         });
  22.     }
  23.    
  24.     if ($carousel.data('next')) {
  25.         var $next = $('#' + $carousel.data('next') );
  26.        
  27.         $next.jcarouselControl({
  28.             target: '+=1',
  29.             carousel: $carousel
  30.         });
  31.     }
  32.    
  33.     if ($carousel.data('pagination')) {
  34.         var $pagination = $('#' + $carousel.data('pagination') );
  35.        
  36.         $pagination
  37.             .on('jcarouselpagination:active', 'li', function() {
  38.                 $(this).addClass('active');
  39.             })
  40.             .on('jcarouselpagination:inactive', 'li', function() {
  41.                 $(this).removeClass('active');
  42.             })
  43.             .on('click', function(e) {
  44.                 e.preventDefault();
  45.             })
  46.             .jcarouselPagination({
  47.                 perPage: 1,
  48.                 item: function(page) {
  49.                     return '<li><a href="#' + page + '">' + page + '</a></li>';
  50.                 },
  51.                 carousel: $carousel
  52.             });
  53.     }
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement