Advertisement
Guest User

multiCarousel

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function () {
  2.     var itemsMainDiv = ('.MultiCarousel');
  3.     var itemsDiv = ('.MultiCarousel-inner');
  4.     var itemWidth = "";
  5.  
  6.     $('.leftLst, .rightLst').click(function () {
  7.         var condition = $(this).hasClass("leftLst");
  8.         if (condition)
  9.             click(0, this);
  10.         else
  11.             click(1, this)
  12.     });
  13.  
  14.     ResCarouselSize();
  15.  
  16.  
  17.     $(window).resize(function () {
  18.         ResCarouselSize();
  19.     });
  20.  
  21.     //this function define the size of the items
  22.     function ResCarouselSize() {
  23.         var incno = 0;
  24.         var dataItems = ("data-items");
  25.         var itemClass = ('.item');
  26.         var id = 0;
  27.         var btnParentSb = '';
  28.         var itemsSplit = '';
  29.         var sampwidth = $(itemsMainDiv).width();
  30.         var bodyWidth = $('body').width();
  31.         $(itemsDiv).each(function () {
  32.             id = id + 1;
  33.             var itemNumbers = $(this).find(itemClass).length;
  34.             btnParentSb = $(this).parent().attr(dataItems);
  35.             itemsSplit = btnParentSb.split(',');
  36.             $(this).parent().attr("id", "MultiCarousel" + id);
  37.  
  38.  
  39.             if (bodyWidth >= 1200) {
  40.                 incno = itemsSplit[3];
  41.                 itemWidth = sampwidth / incno;
  42.             }
  43.             else if (bodyWidth >= 992) {
  44.                 incno = itemsSplit[2];
  45.                 itemWidth = sampwidth / incno;
  46.             }
  47.             else if (bodyWidth >= 768) {
  48.                 incno = itemsSplit[1];
  49.                 itemWidth = sampwidth / incno;
  50.             }
  51.             else {
  52.                 incno = itemsSplit[0];
  53.                 itemWidth = sampwidth / incno;
  54.             }
  55.             $(this).css({ 'transform': 'translateX(0px)', 'width': itemWidth * itemNumbers });
  56.             $(this).find(itemClass).each(function () {
  57.                 $(this).outerWidth(itemWidth);
  58.             });
  59.  
  60.             $(".leftLst").addClass("over");
  61.             $(".rightLst").removeClass("over");
  62.  
  63.         });
  64.     }
  65.  
  66.     //this function used to move the items
  67.     function ResCarousel(e, el, s) {
  68.         var leftBtn = ('.leftLst');
  69.         var rightBtn = ('.rightLst');
  70.         var translateXval = '';
  71.         var divStyle = $(el + ' ' + itemsDiv).css('transform');
  72.         var values = divStyle.match(/-?[\d\.]+/g);
  73.         var xds = Math.abs(values[4]);
  74.         if (e == 0) {
  75.             translateXval = parseInt(xds) - parseInt(itemWidth * s);
  76.             $(el + ' ' + rightBtn).removeClass("over");
  77.  
  78.             if (translateXval <= itemWidth / 2) {
  79.                 translateXval = 0;
  80.                 $(el + ' ' + leftBtn).addClass("over");
  81.             }
  82.         }
  83.         else if (e == 1) {
  84.             var itemsCondition = $(el).find(itemsDiv).width() - $(el).width();
  85.             translateXval = parseInt(xds) + parseInt(itemWidth * s);
  86.             $(el + ' ' + leftBtn).removeClass("over");
  87.  
  88.             if (translateXval >= itemsCondition - itemWidth / 2) {
  89.                 translateXval = itemsCondition;
  90.                 $(el + ' ' + rightBtn).addClass("over");
  91.             }
  92.         }
  93.         $(el + ' ' + itemsDiv).css('transform', 'translateX(' + -translateXval + 'px)');
  94.     }
  95.  
  96.     //It is used to get some elements from btn
  97.     function click(ell, ee) {
  98.         var Parent = "#" + $(ee).parent().attr("id");
  99.         var slide = $(Parent).attr("data-slide");
  100.         ResCarousel(ell, Parent, slide);
  101.     }
  102.  
  103. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement