【问题标题】:slider changes on mouse scroll鼠标滚动时滑块更改
【发布时间】:2017-06-15 04:41:37
【问题描述】:

我在我的网站上使用引导轮播滑块。我想在 mouseScroll 上更改幻灯片。我该怎么做。这段代码可以正常工作,但我想在 mouseScroll 上更改幻灯片 这是我的代码

     <script>
     $(document).ready(function() {
       $("#product_slider").owlCarousel({  
         rtl:true,
         loop:true,                                                           
         margin:4,
         autoplay:false,
         autoplayTimeout:10000,
         autoplayHoverPause:true,
         lazyLoad : true,
         pagination:false,
         nav:true,
          dots: false,
         navText:false ,
         responsive:{
         0:{
             items:1
         },
         500:{
             items:1
         },
         768:{
             items:4
         },
         1200:{
             items:5

         }
        }
      });

     });
</script>

【问题讨论】:

    标签: javascript jquery twitter-bootstrap owl-carousel


    【解决方案1】:

    当您在轮播上滚动鼠标滚轮时,这将使轮播发生变化。我认为在鼠标悬停在轮播上时防止整个页面滚动是明智的,但我没有花时间在这里这样做。
    小提琴https://jsfiddle.net/mikeferrari/z34m1wbo/

    // select the carousel container
    var myelement = document.getElementById("myCarousel"); 
    
    // this function is called every time the mouse wheel is scrolled
    function makeItSo() {
      // this is where you tell it to go to the next slide
      $('.carousel').carousel('next')
    }
    
    myelement.addEventListener('wheel', function(e) {      
        makeItSo();
    });
    
    
    // start your carousel on page load
    $('.carousel').carousel({
      interval: 2000
    })
    

    【讨论】:

    • 但它显示错误“Uncaught TypeError: $(...).carousel is not a function”
    • 您是否已更改它以匹配您的代码?您需要将示例代码中的 myCarousel 替换为您的选择器 .owlCarousel
    猜你喜欢
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多