【问题标题】:Owl carousel with mouse wheel scroll plugin speed带有鼠标滚轮滚动插件速度的猫头鹰旋转木马
【发布时间】:2020-11-05 21:19:57
【问题描述】:

我在Mouse Wheel 插件中使用Owl Carousel 2,因为网站显示了如何实现它: https://owlcarousel2.github.io/OwlCarousel2/demos/mousewheel.html

这是我的例子:https://z-testing.000webhostapp.com/_owlcarousel/

这是我的代码:

owl.on('mousewheel', '.owl-stage', function (e) {
  if (e.deltaY>0) {
      owl.trigger('next.owl');
  } else {
      owl.trigger('prev.owl');
  }
  e.preventDefault();
});

我遇到的问题是滚动不流畅,速度非常快,一次滚动 6-10 张幻灯片,无法使用。 我希望它尽可能像鼠标滚轮滚动一样流畅。

我找到了一个集成了鼠标滚轮插件的灯箱插件并检查了他们是如何做到的,但我只是不知道如何在我的代码中使用它,你能帮我吗?

这是插件:http://fancybox.net

您可以查看Image gallery (ps, try using mouse scroll wheel) 弹出库示例。

如果你下载插件,你可以看到他们是这样实现鼠标滚轮插件的:

if ($.fn.mousewheel) {
    wrap.bind('mousewheel.fb', function(e, delta) {
        if (busy) {
            e.preventDefault();

        } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
            e.preventDefault();
            $.fancybox[ delta > 0 ? 'prev' : 'next']();
        }
    });
}

你能帮我让它与 Owl Carousel 一起正常工作吗?

【问题讨论】:

    标签: javascript jquery owl-carousel mousewheel


    【解决方案1】:

    您需要使用 smartSpeed 功能来设置滚动速度。

    https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html

    var owl = $('.owl-carousel');
    $('.owl-carousel').owlCarousel({
      loop:true,
      margin:0,
      nav:true,
      smartSpeed:1000,
      responsive:{
          0:{
              items:1
          },
          600:{
              items:1
          },
          1000:{
              items:1
          }
      }
    });
    owl.on('mousewheel', '.owl-stage', function (e) {
      if (e.deltaY>0) {
          owl.trigger('next.owl');
      } else {
          owl.trigger('prev.owl');
      }
      e.preventDefault();
    });
    $(document,window,'html').mouseleave(function(){
      $("#footer").fadeOut();
    }).mouseenter(function(){
      $("#footer").fadeIn();
    });
    $(function(){
      $("#header").load("includes/header.html");
      $("#footer").load("includes/footer.html");
    });
    body { padding-top: 0px;}
    <link rel="stylesheet" href="https://z-testing.000webhostapp.com/_owlcarousel/app/css/normalize.css">
    <link rel="stylesheet" href="https://z-testing.000webhostapp.com/_owlcarousel/app/css/owl.carousel.min.css">
    <link rel="stylesheet" href="https://z-testing.000webhostapp.com/_owlcarousel/app/css/owl.theme.default.min.css">
    <link rel="stylesheet" href="https://z-testing.000webhostapp.com/_owlcarousel/app/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://z-testing.000webhostapp.com/_owlcarousel/app/css/main.css">
    
      <header id="header"></header>
    
      <div class="owl-carousel owl-theme">
        <div class="item" style="background-image:url(https://z-testing.000webhostapp.com/_owlcarousel/app/img/carousel-3-ux.png)"></div>
        <div class="item" style="background-image:url(https://z-testing.000webhostapp.com/_owlcarousel/app/img/carousel-4-editorial.png)"></div>
        <div class="item" style="background-image:url(https://z-testing.000webhostapp.com/_owlcarousel/app/img/carousel-5-senaletica.png)"></div>
      </div>
    
      <footer id="footer"></footer>
    
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/vendor/modernizr-3.11.2.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/jquery-3.5.1.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/bootstrap.bundle.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/jquery.justifiedGallery.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/owl.carousel.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/jquery.mousewheel.min.js"></script>
      <script src="https://z-testing.000webhostapp.com/_owlcarousel/app/js/main.js"></script>

    【讨论】:

    • 谢谢,但如果你检查你的 sn-p 它根本不起作用,仍然会出现同样的行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    相关资源
    最近更新 更多