Background-image change in modal javascript

I’m trying something tricky. I’m just trying to amend a javascript code I found to create a modal with slides, and I’m trying to get the background image to change as you scroll through the images. I thought I could just add "return slideIndex;" and a new function that would have a specific background image for every integer (there are 5) of slideIndex. I think I must be misunderstanding the original javascript I am working with.

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

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

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlidesE");
  var dots = document.getElementsByClassName("demoE");
  
  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";

  
  return slideIndex;
}

function changeBG() {
  
    if (slideIndex === 1) {
  document.getElementByClassName(".modalE:before").style.backgroundImage = "linear-gradient(160deg, white, black)";
  }
    else if (slideIndex === 2) {
  document.getElementByClassName(".modalE:before").style.backgroundImage = "linear-gradient(160deg, green, blue)";
  }
  
}

Source: Ask Javascript Questions

LEAVE A COMMENT