当幻灯片不在原始位置时,idangerous swiper link无法正常工作

时间:2013-09-04 12:07:52

标签: jquery html swipe swiper

使用idangerous swiper,请参阅Slide1 lets go to google。如果Slide1位于原始位置(框中的第一个左侧),则谷歌的链接将始终有效。但是如果我们滑动(或鼠标左右拖放)并且Slide1位于第2或第3位,则点击将无效。

http://jsfiddle.net/C8ytu/

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Demo</title>
  <link rel="stylesheet" href="http://www.idangero.us/sliders/swiper/css/idangerous.swiper.css">
  <style>
/* Demo Styles */
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.5;
}
.swiper-container {
  width: 660px;
  height: 250px;
  color: #fff;
  text-align: center;
}
.red-slide {
  background: #ca4040;
}
.blue-slide {
  background: #4390ee;
}
.orange-slide {
  background: #ff8604;
}
.green-slide {
  background: #49a430;
}
.pink-slide {
  background: #973e76;
}
.swiper-slide .title {
  font-style: italic;
  font-size: 42px;
  margin-top: 80px;
  margin-bottom: 0;
  line-height: 45px;
}
.pagination {
  position: absolute;
  z-index: 20;
  left: 10px;
  bottom: 10px;
}
.swiper-pagination-switch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 8px;
  background: #222;
  margin-right: 5px;
  opacity: 0.8;
  border: 1px solid #fff;
  cursor: pointer;
}
.swiper-visible-switch {
  background: #aaa;
}
.swiper-active-switch {
  background: #fff;
}
  </style>
</head>
<body>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide red-slide">
        <div class="title"><a href="http://www.google.com" target="_blank">lets go to google</a></div>
      </div>
      <div class="swiper-slide blue-slide">
        <div class="title">Slide 2</div>
      </div>
      <div class="swiper-slide orange-slide">
        <div class="title">Slide 3</div>
      </div>
      <div class="swiper-slide green-slide">
        <div class="title">Slide 4</div>
      </div>
      <div class="swiper-slide pink-slide">
        <div class="title">Slide 5</div>
      </div>
      <div class="swiper-slide red-slide">
        <div class="title">Slide 6</div>
      </div>
      <div class="swiper-slide blue-slide">
        <div class="title">Slide 7</div>
      </div>
      <div class="swiper-slide orange-slide">
        <div class="title">Slide 8</div>
      </div>
    </div>
    <div class="pagination"></div>
  </div>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://www.idangero.us/sliders/swiper/js/idangerous.swiper.js"></script>

  <script>
  var mySwiper = new Swiper('.swiper-container',{
    pagination: '.pagination',
    paginationClickable: true,
    slidesPerView: 3,
    loop: true
  })
  </script>
</body>
</html>

2 个答案:

答案 0 :(得分:6)

您必须在代码中添加loopAdditionalSlides:3并解决您的问题。

请参见JSFiddle

JS:

var mySwiper = new Swiper('.swiper-container',{
    pagination: '.pagination',
    loopAdditionalSlides:3,    //<-- This one
    paginationClickable: true,
    slidesPerView: 3,
    loop: true
});

loopAdditionalSlides:“创建循环后将克隆的幻灯片数量增加”

Documentation: Swiper Usage and API

答案 1 :(得分:4)

所以在Sliding Right看来标签没有被点击。我只是帮你解决这个问题。在滑动之前先看一下屏幕截图,然后在滑动之后看一下屏幕截图

Swiper before sliding

Swiper after sliding right

我改变了一些代码并且开火了它。看来你的js文件在父div上添加了一种点击

<div class="swiper-slide orange-slide swiper-slide-visible swiper-slide-active" style="width: 165px; height: 250px;">
    <div class="title">Slide 8<br><a href="http://www.google.com" target="_blank">lets go to google</a></div>
  </div>

在父div上添加额外的类

swiper-slide-visible swiper-slide-active

但滑动左侧的相同内容并不是在任何地方添加任何类。它保留默认类

swiper-slide orange-slide

检查JS ......我只能指导你:)如果你希望那么不适合去解决,但如果你可以编辑js点击那么请做。告诉我,如果这不能解决您的问题:)