How to make the change of images smoother in an image slideshow

Hi,

I am working on this page https://kroweb.dk/gfdev/

I have an automatic  slideshow at the top of the page. It is generally working as it is supposed to, except for the change of slides where the next slide is displayed kind of "hard".
What I am after here is that the change of slides displays like a soft ease out of the actual slide and a simultaneously soft ease in of the next slide.

Anybody who have ideas :)

The actual slideshow code is this:
<style>
* {box-sizing: border-box;}
body {font-family: Verdana, sans-serif;}
.mySlides {display: none;}
img {vertical-align: middle;}

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

/* Caption text */
.text {
  display: none;  
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  display: none;  
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

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

.active {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-dealy: 1000;
  -webkit-animation-duration: 3s;
  -webkit-transition-timing-function: ease-in;
  animation-name: fade;
  animation-dealy: 1000;
  animation-duration: 3s;
  transition-timing-function: ease-in;
}

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

@keyframes fade {
  from {opacity: -1} 
  to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .text {font-size: 11px}
}
</style>


<div class="slideshow-container">

<div class="mySlides fade">
  <div class="numbertext">1 / 3</div>
  <img src="https://genealogiskforum.dk/images/GF træf2012 profil 1200x400.jpg" style="width:100%">
  <div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">2 / 3</div>
  <img src="https://genealogiskforum.dk/images/GF træf2013 profil 1200x400.jpg" style="width:100%">
  <div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
  <div class="numbertext">3 / 3</div>
  <img src="https://genealogiskforum.dk/images/GF træf2014 profil 1200x400.jpg" style="width:100%">
  <div class="text">Caption Three</div>
</div>

</div>
<br>

<div style="text-align:center">
  <span class="dot"></span> 
  <span class="dot"></span> 
  <span class="dot"></span> 
</div>

<script>
var slideIndex = 0;
showSlides();

function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    for (i = 0; i < slides.length; i++) {
       slides[i].style.display = "none";  
    }
    slideIndex++;
    if (slideIndex > slides.length) {slideIndex = 1}    
    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";
    setTimeout(showSlides, 5000); // Change image every 2 seconds
}
</script>



    </div>

Open in new window

Peter KromanSenior Proposal SpecialistAsked:
Who is Participating?
 
Leonidas DosasConnect With a Mentor Commented:
Yes... it works nice and smoothly.
0
 
Leonidas DosasCommented:
See this CSS transitions.I use classes hidden and visible to hide and show.I use addClass or removeClass
CSS:
.visible
               {
                       visibility: visible;
                       opacity: 1;
                       transition: opacity 2s linear;
               }                
               /* Fade-Out Effect */
               .hidden
               {
                       visibility: hidden;
                       opacity: 0;
                       transition: visibility 0s 2s, opacity 2s linear;
               }

Open in new window


Sample Code below:
<!DOCTYPE html>
<html>
<head>
<title>HTML, CSS and JavaScript demo</title>
  <style>
   .visible
               {
                       visibility: visible;
                       opacity: 1;
                       transition: opacity 2s linear;
               }                
               /* Fade-Out Effect */
               .hidden
               {
                       visibility: hidden;
                       opacity: 0;
                       transition: visibility 0s 2s, opacity 2s linear;
               }                
               #wrapper > div
               {
                       background: none repeat scroll 0 0 #f5f;
                       border: 5px solid #808080;
                       border-radius: 50px;
                       padding: 10px;
                       width: 250px;
               }
  </style>
</head>
<body>
<!-- Start your code here -->

<div id="wrapper">
               <p>
                       <button type="button">Show HTML Element</button>
                       <button type="button">Hide HTML Element</button>
               </p>
               <br />
               <div class="hidden">
                       Hello Peter
               </div>
       </div>
  <script>
     var showButtonClick = document.querySelector("#wrapper button:nth-of-type(1)"),
                       hideButtonClick = document.querySelector("#wrapper button:nth-of-type(2)"),
                       content = document.querySelector("#wrapper > div");
               //Show wrapper div content
               showButtonClick.addEventListener("click", function () {
                       content.className = "visible";
               }, false);

               //Hide wrapper div content
               hideButtonClick.addEventListener("click", function () {
                       content.className = "hidden";
               }, false);
  </script>
<!-- End your code here -->
</body>
</html>

Open in new window

0
 
Peter KromanSenior Proposal SpecialistAuthor Commented:
Thanks Leonidas,

I'll work with it and get back to you
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Peter KromanSenior Proposal SpecialistAuthor Commented:
Hi again,

I can't get it working right. Could I aks you to give me an example with a couple of images that slides automatically (no buttons) and with the nice fade-in and fade-out look :)
0
 
Peter KromanSenior Proposal SpecialistAuthor Commented:
Hi again,

I have managed to make a much simpler code that the first one I posted.
And it is working nicely :)

HTML:
<div id="slideshow">
       <div>
         <img src="https://genealogiskforum.dk/images/GF træf2012 profil 1200x400.jpg" width="100%">
       </div>
       <div>
         <img src="https://genealogiskforum.dk/images/GF træf2013 profil 1200x400.jpg" width="100%">
       </div>
       <div>
         <img src="https://genealogiskforum.dk/images/GF træf2014 profil 1200x400.jpg" width=100%>
       </div>
       <div>
         <img src="https://genealogiskforum.dk/images/Gf træf2015 profil 1200x400.jpg" width="100%">
       </div>
       <div>
         <img src="https://genealogiskforum.dk/images/GF træf2016 profil 1200x400.jpg" width="100%">
       </div>
       <div>
         <img src="https://genealogiskforum.dk/images/Gf træf2017 profil 1200x400.jpg" width="100%">
       </div>
    </div>

Open in new window


CSS:
#slideshow { 
    position: relative; 
    width: 100%; 
    
}

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

Open in new window


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

        setInterval(function() { 
          $('#slideshow > div:first')
            .fadeOut(2500)
            .next()
            .fadeIn(2500)
            .end()
            .appendTo('#slideshow');
        },  5000);

Open in new window

0
 
Peter KromanSenior Proposal SpecialistAuthor Commented:
Thanks for leading me in the right direction on this one :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.