How can I change the slide index on a hidden div?

Viewed 59

I don't know javascript and could use some help. I have a lightbox that pops up but I can't change the slide index # - it works if it's not hidden. is there a way to fix it? I have 10 images numbered 1-10 for the light box and looking for the first one to pop up to be #10 instead of #1

EXAMPLE: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_js_lightbox - trying to change the "currentSlider" to show in descending order when popped up

<script>
// Open the Modal
function openModal() {
  $('#myModal').toggleClass('mod-act');
  $("#popOverlay").fadeIn();
}

// Close the Modal
function closeModal() {
  $('#myModal').removeClass('mod-act');
  $("#popOverlay").fadeOut();
}

var slideIndex = 3;// MY ISSUE STARTS HERE
showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controls
function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("demo");

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

If you can't work with the hidden element, so you can set opacity = 0 instead of display none and set position absolute to make them place in the same line.

Related