admin管理员组

文章数量:1287608

There are two owlCarousel working perfectly in one page but I want to change the default setting on each carousel. Once I changed the effects applying to both carousel.

What I've already tried

<script>
    $(document).ready(function() {
      $("#owl-demo").owlCarousel1({
        navigation : false,
        pagination : true,
        items : 1
      });
    });

</script>
<script>
    $(document).ready(function() {

    $("#owl-example").owlCarousel();


    });
</script>

I want to change the below settings for each carousle

 $.fn.owlCarousel.options = {

        items : 4,
        itemsCustom : false,
        itemsDesktop : [1199, 1],
        itemsDesktopSmall : [979, 1],
        itemsTablet : [768, 1],
        itemsTabletSmall : false,
        itemsMobile : [479, 1],
        singleItem : false,
        itemsScaleUp : false
}

There are two owlCarousel working perfectly in one page but I want to change the default setting on each carousel. Once I changed the effects applying to both carousel.

What I've already tried

<script>
    $(document).ready(function() {
      $("#owl-demo").owlCarousel1({
        navigation : false,
        pagination : true,
        items : 1
      });
    });

</script>
<script>
    $(document).ready(function() {

    $("#owl-example").owlCarousel();


    });
</script>

I want to change the below settings for each carousle

 $.fn.owlCarousel.options = {

        items : 4,
        itemsCustom : false,
        itemsDesktop : [1199, 1],
        itemsDesktopSmall : [979, 1],
        itemsTablet : [768, 1],
        itemsTabletSmall : false,
        itemsMobile : [479, 1],
        singleItem : false,
        itemsScaleUp : false
}
Share Improve this question edited Sep 17, 2014 at 11:55 Joshua Taylor 85.9k9 gold badges161 silver badges362 bronze badges asked Sep 17, 2014 at 11:03 Nasir JavedNasir Javed 411 gold badge1 silver badge2 bronze badges 1
  • Please read the tag descriptions carefully; this question is not about owl, whose description is "The Web Ontology Language (OWL) is a vocabulary for creating schemas (ontologies), i.e. definitions of classes, properties and the relationships between them." You should have used the owl-carousel tag. – Joshua Taylor Commented Sep 17, 2014 at 11:54
Add a ment  | 

4 Answers 4

Reset to default 5

If you assign a variable to each of the div's you wish to target and then assign the options, example below;

$(document).ready(function() {
   var one = $("#one");
   var two = $("#two");

  one.owlCarousel({
      navigation : false, // Show next and prev buttons
      slideSpeed : 300,
      paginationSpeed : 400,
      singleItem:true,
      mouseDrag:false,
      touchDrag:false
  });  

two.owlCarousel({
  navigation : true, // Show next and prev buttons
  slideSpeed : 300,
  paginationSpeed : 400,
  singleItem:true,
  mouseDrag:false,
  touchDrag:false,
  navigationText : false,
  rewindSpeed : 300,
  });

});

there are tow things you must do to let every owl slider have its own trigger
1- each one have it's own assignment like above

    $(document).ready(function() {
   var one = $("#one");
   var two = $("#two");

  one.owlCarousel({
      navigation : false, // Show next and prev buttons
      slideSpeed : 300,
      paginationSpeed : 400,
      singleItem:true,
      mouseDrag:false,
      touchDrag:false
  });  

two.owlCarousel({
  navigation : true, // Show next and prev buttons
  slideSpeed : 300,
  paginationSpeed : 400,
  singleItem:true,
  mouseDrag:false,
  touchDrag:false,
  navigationText : false,
  rewindSpeed : 300,
  });

});

2- change the button class name
1st slider

<div class="customNavigation">
                    <a class="btn prev_one"><i class="fa fa-backward" aria-hidden="true"></i></a>
                    <a class="btn next_one"><i class="fa fa-forward" aria-hidden="true"></i></a>
                    <a class="btn play_one"><i class="fa fa-play" aria-hidden="true"></i></a>
                    <a class="btn stop_one"><i class="fa fa-pause" aria-hidden="true"></i></a>
                </div>

2nd Slider

<div class="customNavigation">
                    <a class="btn prev_two"><i class="fa fa-backward" aria-hidden="true"></i></a>
                    <a class="btn next_two"><i class="fa fa-forward" aria-hidden="true"></i></a>
                    <a class="btn play_two"><i class="fa fa-play" aria-hidden="true"></i></a>
                    <a class="btn stop_two"><i class="fa fa-pause" aria-hidden="true"></i></a>
                </div>

I wish it could be fine for you all

To change the class of the nav or dots you can use the class options provided by Owl Carousel (https://owlcarousel2.github.io/OwlCarousel2/docs/api-classes.html)

$(document).ready(function() {
   var one = $("#one");
   var two = $("#two");

  one.owlCarousel({
      navContainerClass: '//YOUR CUSTOM CLASS',
      dotsClass: '//YOUR CUSTOM CLASS'
  });  

  two.owlCarousel({
    navContainerClass: '//YOUR CUSTOM CLASS',
    dotsClass: '//YOUR CUSTOM CLASS'
  });

});

js code

    $("#fr-car").owlCarousel({
    items: 1,
    loop: false,
    autoplay: true,
    animateOut: 'fadeOut',
    autoplayTimeout: 3000,
    nav: true,
    autoplayHoverPause: true
  });
  $('#nd-car').owlCarousel({
    responsive:{
      0:{
          items:1,
          nav:true
      },
      600:{
          items:3,
          nav:false
      },
      1000:{
          items:5,
          nav:true,
          loop:false
      }
  }
  })

HTML Code

<div id="fr-car" class="owl-carousel">
  <div></div>
  <div></div>
  <div></div>
</div


<div id="nd-car" class="owl-carousel" >
  <div></div>
  <div></div>
  <div></div>
</div

本文标签: javascriptMutlple owl Carousel in one page with different settingStack Overflow