【问题标题】:Mutlple owl Carousel in one page with different setting一页中的多个猫头鹰轮播,具有不同的设置
【发布时间】:2014-09-17 11:03:37
【问题描述】:

有两个 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
}

【问题讨论】:

  • 请仔细阅读标签说明;这个问题与owl 无关,他的描述是“Web 本体语言(OWL)是用于创建模式(本体)的词汇表,即类、属性和它们之间的关系的定义。”你应该使用owl-carousel 标签。

标签: javascript jquery html slider owl-carousel


【解决方案1】:

如果您为每个要定位的 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,
  });

});

【讨论】:

    【解决方案2】:

    您必须做两件事才能让每个猫头鹰滑块都有自己的触发器
    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>
    

    希望大家都好

    【讨论】:

      【解决方案3】:

      要更改导航或点的类,您可以使用 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'
        });
      
      });

      【讨论】:

        【解决方案4】:

        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
        

        【讨论】:

        • 在为一个将近六年的问题添加答案时,重要的是要在解释中指出它的工作原理和原因,以及此代码相对于三个现有答案的优势。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多