Skip to content Skip to sidebar Skip to footer

Using Multiple (owl) Carousel On A Single Page

I have been looking at ways on google to use multiple carousel on a single page and yet did not find any of the solutions working for me. Can anyone of you please help. Here is the

Solution 1:

Updated code should look like this: https://jsfiddle.net/wtg76spd/1/

JavaScript:

$(document).ready(function() {

  $("#owl-demo, #owl-demo-1").each(function() {
    $(this).owlCarousel({
      items : 6, //10 items above 1000px browser width
      itemsDesktop : [1000,6], //5 items between 1000px and 901px
      itemsDesktopSmall : [900,3], // 3 items betweem 900px and 601pxitemsTablet: [600,2], //2 items between 600 and 0;
      itemsMobile : false// itemsMobile disabled - inherit from itemsTablet option
    });
  });
  // Custom Navigation Events
  $(".next").click(function(){$(this).closest('.span12').find('.owl-carousel').trigger('owl.next');})
  $(".prev").click(function(){$(this).closest('.span12').find('.owl-carousel').trigger('owl.prev');})
});

CSS (just first line changed):

//before
 #owl-demo .item{
//after
 #owl-demo .item, #owl-demo-1 .item{
//class "owl-demo" would do better in this case

1) Use .each() instead of copying code.

2) It'd be better to use class instead of #owl-demo and #owl-demo-1 - let's say you had not 2 but 100 sliders. Would you still give them IDs? However I didn't change it in example.

3) I used closest() and find() methods for next/prev buttons. This way I have 2 callback functions instead of 4.

Post a Comment for "Using Multiple (owl) Carousel On A Single Page"