图像轮播/幻灯片显示上一个/下一个按钮

时间:2017-04-07 10:44:49

标签: javascript jquery html css

我已按照w3school

的说明进行操作

现在我想用指标的prev / next改进它,而不是滑块

这就是我想要实现的目标

example

这也是我的代码

example

OR

var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n) {
  showDivs(slideIndex += n);
}

function currentDiv(n) {
  showDivs(slideIndex = n);
}

function showDivs(n) {
  var i;
  var x = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("demo");
  if (n > x.length) {slideIndex = 1}
  if (n < 1) {slideIndex = x.length}
  for (i = 0; i < x.length; i++) {
     x[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
     dots[i].className = dots[i].className.replace(" w3-opacity-off", "");
  }
  x[slideIndex-1].style.display = "block";
  dots[slideIndex-1].className += " w3-opacity-off";
}
#indi {
  width: 200px;
  float:left;
}
<body>

<div class="w3-content" style="max-width:1200px">
  <img class="mySlides" src="https://www.w3schools.com/w3css/img_mountains.jpg" style="width:100%">
  <img class="mySlides" src="https://www.w3schools.com/w3css/img_fjords_wide.jpg" style="width:100%">
  <img class="mySlides" src="https://www.w3schools.com/w3css/img_mountains_wide.jpg" style="width:100%">

  <div class="w3-row-padding w3-section">
    <div  id="indi" class="w3-col s4">
      <img  class="demo w3-opacity w3-hover-opacity-off" src="https://www.w3schools.com/w3css/img_nature_wide.jpg" style="width:100%" onclick="currentDiv(1)">
    </div>
    <div id="indi" class="w3-col s4">
      <img class="demo w3-opacity w3-hover-opacity-off" src="https://www.w3schools.com/w3css/img_fjords_wide.jpg" style="width:100%" onclick="currentDiv(2)">
    </div>
    <div id="indi" class="w3-col s4">
      <img  class="demo w3-opacity w3-hover-opacity-off" src="https://www.w3schools.com/w3css/img_mountains_wide.jpg" style="width:100%" onclick="currentDiv(3)">
    </div>
  </div>
</div>

</body>

在此之前,感谢任何帮助

1 个答案:

答案 0 :(得分:2)

下一步:

$("#next").click(function () {
$("#container div:eq(" + num + ")").slideUp(450);
num = (num + 1) % 4;
$("#container div:eq(" + num + ")").fadeIn(450);
});

最后:

$("#last").click(function () {
$("#container div:eq(" + num + ")").slideUp(450);
num = 4;
$("#container div:eq(" + num + ")").fadeIn(450);
});

已经提出并回答了问题 - How do I add buttons to my Javascript/Jquery Slider?

如果您需要更具体的帮助,请不要犹豫。