将猫头鹰旋转木马放入不同设置的页面中

Mutlple owl Carousel in one page with different setting

本文关键字:设置 猫头鹰 旋转木马      更新时间:2023-09-26

一个页面中有两个owlCarousel可以完美工作,但我想更改每个转盘的默认设置。有一次我改变了适用于两个旋转木马的效果。

我已经尝试过

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

    });
</script>

我想更改每个胡萝卜的以下设置

 $.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
}

如果将一个变量分配给每个要作为目标的div,然后分配选项,示例如下;

$(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,
  });
});

要让每个owl滑块都有自己的触发器,必须做两件事
1-每个人都有自己的任务,如上所述

    $(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-更改按钮类名
第一个滑块

<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>

第二滑块

<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>

我希望它能对你们所有人都很好。

要更改导航或点的类,可以使用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代码
    $("#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代码

<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