动态滑块双内容显示

时间:2017-07-29 22:02:12

标签: javascript php css mysql mysqli

我试图让W3滑块动态显示原始滑块来自this-link

我想以这样的方式制作它只显示所有底部图像,而只显示顶部的当前图像,以便更好地理解 this-link

我的代码Everythings显示为double。

这是我的滑块代码:

       <section id="slider">
    <div class="container wow fadeInUp">
      <div class="row">
        <div class="col-md-12">
         <h3 class="section-title">Photo Gallery</h3>
         <div class="section-title-divider"></div>
  <div class="w3-content" style="max-width:1200px">
                                                                <?php 

include("admin/db/db.php");


$select_db = "select * from gallery";

$run_events = mysql_query($select_db);

while($row=mysql_fetch_array($run_events)){


    $id = $row['id'];
      $image= $row['image'];

?>
  <img class="mySlides" src="admin/images/gallery/<?php echo $image; ?>" style="width:100%;height:350px;">
  <div class="w3-row-padding w3-section">
    <div class="w3-col s4">
      <img class="demo w3-opacity w3-hover-opacity-off" src="admin/images/gallery/<?php echo $image; ?>" style="width:100%" onclick="currentDiv(<?php echo $id; ?>)">
    </div>
<?php }?>

  </div>
</div>
<script>
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";
}
</script>

        </div>
      </div>
    </div>

  </section> 

1 个答案:

答案 0 :(得分:0)

您需要用此替换代码,并参阅:

<section id="slider">
    <div class="container wow fadeInUp">
      <div class="row">
        <div class="col-md-12">
         <h3 class="section-title">Photo Gallery</h3>
         <div class="section-title-divider"></div>
  <div class="w3-content" style="max-width:1200px">

<?php 

include("admin/db/db.php");

$select_db = "select * from gallery";
$run_events = mysql_query($select_db);
while($row=mysql_fetch_array($run_events)){

    $id = $row['id'];
      $image= $row['image'];

?>
  <img class="mySlides" src="admin/images/gallery/<?php echo $image; ?>" style="width:100%;height:350px;">
  <div class="w3-row-padding w3-section">
    <div class="w3-col s4">
      <img class="demo w3-opacity w3-hover-opacity-off" src="admin/images/gallery/<?php echo $image; ?>" style="width:100%" onclick="currentDiv(<?php echo $id; ?>)">
    </div>
  </div>
<?php }?>

</div>

<script>
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";
}
</script>

        </div>
      </div>

    </div>
</section>