htmlcssslideshowadobe-brackets

My Image Carousel is not working? (HTML & CSS)


I am trying to make an Image Carousel for a website, I coded the thing in brackets, which shows in the brackets live preview that it looks like this : [image of the brackets live preview window]

yet when I open it in Chrome by clicking on my index.js it makes the first image decide not to appear yet the second image appears.

and when I upload the code to github website and completely refresh it. it looks like this [image of the first image on the github site]

it isnt even in it's container that I coded for it.

and when i click on the arrow it takes me to the next photo which displays as this [second image on the github site]

its as if it isnt even creating the container and inserting the image into it..

my code looks like this:

var slideIndex = 1;
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("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";
    
    
}
outer {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideInRight ease 1s;
}

  @keyframes slideInRight {
  0% {
    opacity: 1;
    transform: translate3d(100%, 0, 0);
  }

  100% {
    opacity: 1;
    transform: none;
  }
}


.wrapper {
    display: grid;
    grid-template-columns: 1fr;
    grid-gap: 100px;
    margin-top: 75px;
    align-content: center;
    text-align: center
}
.element {
    display: grid;
    grid-template-areas: "dsc lgo" "ttl lgo";
    grid-template-rows: auto 1fr;
    grid-template-columns: auto 1fr;
    grid-gap: 10px;
  animation: fadeInAnimation ease 2s;
}
        @keyframes fadeInAnimation { 
            0% { 
                opacity: 0; 
            } 
            
            50% { 
                opacity: 0; 
            } 
            
            100% { 
                opacity: 1; 
            } 
        } 


/* Slideshow container */

.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

/* Hide the images by default */
.mySlides {
  display: none;
}

/* Next & previous buttons */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* Position the "next button" to the right */
.prev {
  left: 0;
  border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 0px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
  background-color: rgba(26, 26, 26, 0.6);
  margin-bottom: 20px;

}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: #717171;
}

/* Sliding animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4}
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4}
  to {opacity: 1}
}
    <div class='outer'>
            
                    <div class='wrapper'>
            <div class='element'>
            <!-- Slideshow container -->
<!-- Slideshow container -->
<div class="slideshow-container">

  <!-- Full-width images with number and caption text -->
  <div class="mySlides fade">
    <img src="/images/wallpaper2you_482698.jpg" style="width:100%">
    <div class="text">Caption Text</div>
  </div>

  <div class="mySlides fade">
    <img src="images/wwwallpaper2you_482698.jpg" style="width:100%">
    <div class="text">Caption Two</div>
  </div>

  <div class="mySlides fade">
    <img src="images/wwallpaper2you_482698.jpg" style="width:100%">
    <div class="text">Caption Three</div>
  </div>

  <!-- Next and previous buttons -->
  <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  <a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<br>

<!-- The dots/circles -->
<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>
                        </div>
            </div>
    </div>

can anyone please help me!?


Solution

  • Your source code is ok, just recheck your image path file. Else wipe out the data completely on github and then re-upload it.

        var slideIndex = 1;
    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("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";
        
        
    }
    outer {
        display: flex;
        align-items: center;
        justify-content: center;
        animation: slideInRight ease 1s;
    }
    
      @keyframes slideInRight {
      0% {
        opacity: 1;
        transform: translate3d(100%, 0, 0);
      }
    
      100% {
        opacity: 1;
        transform: none;
      }
    }
    
    
    .wrapper {
        display: grid;
        grid-template-columns: 1fr;
        grid-gap: 100px;
        margin-top: 75px;
        align-content: center;
        text-align: center
    }
    .element {
        display: grid;
        grid-template-areas: "dsc lgo" "ttl lgo";
        grid-template-rows: auto 1fr;
        grid-template-columns: auto 1fr;
        grid-gap: 10px;
      animation: fadeInAnimation ease 2s;
    }
            @keyframes fadeInAnimation { 
                0% { 
                    opacity: 0; 
                } 
                
                50% { 
                    opacity: 0; 
                } 
                
                100% { 
                    opacity: 1; 
                } 
            } 
    
    
    /* Slideshow container */
    
    .slideshow-container {
      max-width: 1000px;
      position: relative;
      margin: auto;
    }
    
    /* Hide the images by default */
    .mySlides {
      display: none;
    }
    
    /* Next & previous buttons */
    .prev, .next {
      cursor: pointer;
      position: absolute;
      top: 50%;
      width: auto;
      margin-top: -22px;
      padding: 16px;
      color: white;
      font-weight: bold;
      font-size: 18px;
      transition: 0.6s ease;
      border-radius: 0 3px 3px 0;
      user-select: none;
    }
    
    /* Position the "next button" to the right */
    .next {
      right: 0;
      border-radius: 3px 0 0 3px;
    }
    
    /* Position the "next button" to the right */
    .prev {
      left: 0;
      border-radius: 3px 0 0 3px;
    }
    
    /* On hover, add a black background color with a little bit see-through */
    .prev:hover, .next:hover {
      background-color: rgba(0,0,0,0.8);
    }
    
    /* Caption text */
    .text {
      color: #f2f2f2;
      font-size: 15px;
      padding: 8px 0px;
      position: absolute;
      bottom: 8px;
      width: 100%;
      text-align: center;
      background-color: rgba(26, 26, 26, 0.6);
      margin-bottom: 20px;
    
    }
    
    /* The dots/bullets/indicators */
    .dot {
      cursor: pointer;
      height: 15px;
      width: 15px;
      margin: 0 2px;
      background-color: #bbb;
      border-radius: 50%;
      display: inline-block;
      transition: background-color 0.6s ease;
    }
    
    .active, .dot:hover {
      background-color: #717171;
    }
    
    /* Sliding animation */
    .fade {
      -webkit-animation-name: fade;
      -webkit-animation-duration: 1.5s;
      animation-name: fade;
      animation-duration: 1.5s;
    }
    
    @-webkit-keyframes fade {
      from {opacity: .4}
      to {opacity: 1}
    }
    
    @keyframes fade {
      from {opacity: .4}
      to {opacity: 1}
    }
    <div class='outer'>
                
                        <div class='wrapper'>
                <div class='element'>
                <!-- Slideshow container -->
    <!-- Slideshow container -->
    <div class="slideshow-container">
    
      <!-- Full-width images with number and caption text -->
      <div class="mySlides fade">
        <img src="a.jpg" style="width:100%">
        <div class="text">Caption Text</div>
      </div>
    
      <div class="mySlides fade">
        <img src="d.jpg" style="width:100%">
        <div class="text">Caption Two</div>
      </div>
    
      <div class="mySlides fade">
        <img src="w.jpg" style="width:100%">
        <div class="text">Caption Three</div>
      </div>
    
      <!-- Next and previous buttons -->
      <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
      <a class="next" onclick="plusSlides(1)">&#10095;</a>
    </div>
    <br>
    
    <!-- The dots/circles -->
    <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>
                            </div>
                </div>
        </div>