简体   繁体   中英

dynamic slider double content displaying

Im trying to make a W3 slider dynamic the original slider is from this-link

i want to make it in a way that it only displys all the bottom images and only current image at the top see this-link for better understanding.

with my code everythings is displayed double.

This is my code for the slider:

       <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> 

You need to replace your code with this and see:

<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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM