简体   繁体   中英

How to include SlideShow and ImageComparison

I´d like to include this script and this script together. Separately it works like a charm. But from some reason both together it´s not working.

I suppose the problem would be somewhere here (probably to correct somehow previous/next slide script ), but I don´t know how to fix it. May I please ask for help? Thank you!

// Read photos in directory
if ($handle = opendir('src/images/')) {
$i = 0;
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
           $a[] = $entry;
            $i++;
        }
    }
    closedir($handle);
}
// Display photos
while ($i != 0)
{
echo '
<div class="mySlides fade">
  <div class="numbertext">1 / 3</div>
   <div class="wrapper">
    <div class="js-comparison-container" start-position="50"  style="max-width: 60%;">
      <img class="comparison-image" src="src/images/'.$a[$i-2].'" alt="" style="width: 100 %";>    
      <img class="comparison-image" src="src/images/'.$a[$i-1].'" alt="" style="width: 100 %";>
   </div>                                                                  
  </div>
  <div class="text">' . $a[$i-2]." a " . $a[$i-1]. '<br></div>
</div>


<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>

';
$i = $i-2;
}
?>
</div>
<br>
<div style="text-align:center">
  <span class="dot" onclick="currentSlide(1)"></span> 
  <span class="dot" onclick="currentSlide(2)"></span>
  <span class="dot" onclick="currentSlide(3)"></span> 
</div>
// Script for the previous/next slide
<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {slideIndex = 1}    
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";  
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
}
</script>

我通过 $_SESSION 和 $_GET 方法解决了它(没有上面提到的幻灯片脚本)。

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