Search code examples
javascriptslideshow

what can a simple slideshow look like


i have an example of a simple slideshow. unfortunately the transition to the last picture doesn't work as well as with the other two.

$("#slideshow > div:gt(0)").hide();

setInterval(function() {
  $('#slideshow > div:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('#slideshow');
}, 3000);
#slideshow {
  margin: 80px auto;
  position: relative;
  width: 1229px;
  height: 858px;
  padding: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
}

#slideshow>div {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
}

img {
  width: 100%;
  height: 100%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="slideshow">
  <div>
    <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041942_RPytRGKfSKx4Yk4NV0RZ0sqcpx8ZSEak.jpg">
  </div>
  <div>
    <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041959_VCKjqtEbr2te6x1P7z6g5xHYCFAnua6G.jpg">
  </div>
  <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041948_wv0NLtMeGfunrFb00kLYSokk1eYM2ygo.jpg">
</div>
</div>

I can't find the error :(. Do you have an idea or even a better one. Thanks


Solution

  • $("#slideshow > div:gt(0)").hide();
    
    setInterval(function() {
      $('#slideshow > div:first')
        .fadeOut(1000)
        .next()
        .fadeIn(1000)
        .end()
        .appendTo('#slideshow');
    }, 3000);
    #slideshow {
      margin: 80px auto;
      position: relative;
      width: 1229px;
      height: 858px;
      padding: 10px;
      box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
    }
    
    #slideshow>div {
      position: absolute;
      top: 10px;
      left: 10px;
      right: 10px;
      bottom: 10px;
    }
    
    img {
      width: 100%;
      height: 100%
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div id="slideshow">
      <div>
        <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041942_RPytRGKfSKx4Yk4NV0RZ0sqcpx8ZSEak.jpg">
      </div>
      <div>
        <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041959_VCKjqtEbr2te6x1P7z6g5xHYCFAnua6G.jpg">
      </div>
      <div>
      <img src="https://as2.ftcdn.net/jpg/02/68/04/19/500_F_268041948_wv0NLtMeGfunrFb00kLYSokk1eYM2ygo.jpg">
    </div>
    </div>