如何在响应式幻灯片中添加播放按钮



我有一组图像可以使用响应式幻灯片显示。我找到了一个创建响应式幻灯片的链接:http://responsiveslides.com。我不知道在幻灯片中添加暂停/播放按钮。我的代码如下:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
  <script src="../responsiveslides.min.js"></script>
  <script>
      $("#slider4").responsiveSlides({
        auto: true,
        pager: false,
        pauseControls:true,
        nav: true,
        pause: false,
        speed: 500,
        namespace: "callbacks",
        before: function () {
          $('.events').append("<li>before event fired.</li>");
        },
        after: function () {
          $('.events').append("<li>after event fired.</li>");
        }
      });
    });
  </script>
</head>
<body>
  <div id="wrapper">
      <a class="pause_slider" href="#">Pause Slider</a>
      <a class="play_slider" href="#">Play Slider</a>

    <div class="callbacks_container">
      <ul class="rslides" id="slider4">
        <li>
          <img src="images/1.jpg" alt="">
          <p class="caption">This is a caption</p>
        </li>
        <li>
          <img src="images/2.jpg" alt="">
          <p class="caption">This is another caption</p>
        </li>
        <li>
          <img src="images/3.jpg" alt="">
          <p class="caption">The third caption</p>
        </li>
      </ul>
    </div>

以上是源代码。如何在幻灯片中添加暂停和播放按钮?

您是否必须使用该库,或者您可以收听其他选项?

我建议你刷卡。在我看来,这是一个更好的库。这是入门链接。

在此示例中,您可以使用方法start()(自动播放滑块(和stop()(暂停滑块(更改布尔autoplay的值。

这里有一个例子。希望它有帮助:

$(document).ready(function() {
	new Swiper('.swiper-container', {
		speed: 600,
		spaceBetween: 90,
		autoplay: true,
		disableOnInteraction: true,
		loop: true
	});
	const mySwiper = document.querySelector('.swiper-container').swiper;
	let isSliderActive = true;
	$("#slider-control").click(function() {
		if (isSliderActive) {
			mySwiper.autoplay.stop();
			isSliderActive = false;
			this.innerHTML = 'PLAY';
			console.log('slider stopped');
		} else {
			mySwiper.autoplay.start();
			isSliderActive = true;
			this.innerHTML = 'PAUSE';
			console.log('slider activated');
		}
	});
});
<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.0.5/js/swiper.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.5/css/swiper.css" rel="stylesheet" />
<style>
	.swiper-slide { text-align: center; }
</style>
<div class="swiper-container">
  <!-- required wrapper -->
  <div class="swiper-wrapper">
    <!-- Slides -->
    <div class="swiper-slide">
		<img src="https://place-hold.it/100x100">
		<div>Slide 1</div>
	</div>
    <div class="swiper-slide">
		<img src="https://place-hold.it/100x100">
		<div>Slide 2</div>
	</div>
    <div class="swiper-slide">
		<img src="https://place-hold.it/100x100">
		<div>Slide 3</div>
    </div>
  </div>
</div>
<button id="slider-control">PAUSE</button>

如果您可以使用其他插件。 哇滑块 默认情况下,您将获得暂停和播放按钮。

相关内容

  • 没有找到相关文章

最新更新