刷卡自动播放。当您移动鼠标光标时,请停止滑动,而当您将鼠标光标从滑动器上移开时,则开始播放

时间:2018-10-28 03:14:23

标签: javascript jquery html5 swiper

单击按钮时,滑动器会在幻灯片中翻转并自动播放,但是当鼠标光标悬停在特定的滑动器上时,滑动器不会停止。可能是个错误吗?

P.S。用github刷牙。 https://github.com/nolimits4web/Swiper/blob/master/demos/280-autoplay.html

int count = 0;
while( first <= last )
{ 
  if ( a[middle] < num_search ) {
    count+= 1;
    first = middle + 1;  
  }  
  else if ( a[middle] == num_search )
 {
   count+= 2;
   System.out.println(num_search + " found at location " + (middle + 1) + ".");
    break;
  }
  else {
      count+= 3;
     last = middle - 1;
 }

  middle = (first + last)/2;
}
System.out.println("Counter = " + count);

1 个答案:

答案 0 :(得分:1)

您可以使用swiper.autoplay.stop()暂停mouseover上的自动播放 和swiper.autoplay.start()上的mouseout重新开始自动播放。

检查根据您提供的链接制作的代码段。

var swiper = new Swiper('.swiper-container', {
  spaceBetween: 30,
  centeredSlides: true,
  autoplay: {
    delay: 2500,
    disableOnInteraction: false,
  },
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
  },
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
});

// now add mouseover and mouse out events on '.swiper-slide' elemnts to pause and resume the autoplay;

$('.swiper-slide').on('mouseover', function() {
  swiper.autoplay.stop();
});

$('.swiper-slide').on('mouseout', function() {
  swiper.autoplay.start();
});
html,
body {
  position: relative;
  height: 100%;
}

body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}

.swiper-container {
  width: 100%;
  height: 100%;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.1/js/swiper.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.1/css/swiper.min.css" rel="stylesheet" />


<div class="swiper-container">
  <div class="swiper-wrapper">
    <div class="swiper-slide">Slide 1</div>
    <div class="swiper-slide">Slide 2</div>
    <div class="swiper-slide">Slide 3</div>
    <div class="swiper-slide">Slide 4</div>
    <div class="swiper-slide">Slide 5</div>
    <div class="swiper-slide">Slide 6</div>
    <div class="swiper-slide">Slide 7</div>
    <div class="swiper-slide">Slide 8</div>
    <div class="swiper-slide">Slide 9</div>
    <div class="swiper-slide">Slide 10</div>
  </div>
  <!-- Add Pagination -->
  <div class="swiper-pagination"></div>
  <!-- Add Arrows -->
  <div class="swiper-button-next"></div>
  <div class="swiper-button-prev"></div>
</div>