如何使滑块在同一图像单击或此功能单击中再次播放?

时间:2018-09-14 06:16:45

标签: javascript jquery owl-carousel owl-carousel-2

代码如下。

$(document).ready(function(){
    $(".owl-carousel").owlCarousel({
      items: 1,
      loop: true,autoplay: true,
      autoplayTimeout: 5000,
      autoplayHoverPause: true,nav: true
       });
       $(".owl-item").click(function(){
       $(".owl-stage").trigger('stop.autoplay.owl');
       $(this).toggleClass('active');
      });
    }); 

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式保存轮播状态:

 let isBlocked = false;
 const owl = $(".owl-carousel")
 owl.owlCarousel({
        items: 1,
        loop: true,
        autoplay: true,
        autoplayTimeout: 5000,
        autoplayHoverPause: true,
        nav: true
  });

  $(".owl-item").click(function(){
      // trigger which event should be fired

      if(isBlocked) {
         owl.trigger('stop.autoplay.owl');
      else {
        owl.trigger('play.autoplay.owl', [1000])
      }
      $(this).toggleClass('active');
      isBlocked = !isBlocked
 });