Md. Riasat Azim
Md. Riasat Azim

Reputation: 1

How to add Ease-in-out effect with JavaScript

Well, I'm new at javascript, I'm learning. Now I want to add an effect of ease in this code..how do I do that?

let slideIndex = 0;

const showSlides = () => {
    const slides = document.getElementsByClassName("slide");

    for(let i = 0; i < slides.length; i++){
    slides[i].style.display = "none";
    }

    slideIndex++;

    if(slideIndex > slides.length){
    slideIndex = 1;
    }

    slides[slideIndex - 1].style.display = "block";
    setTimeout(showSlides,3000);
};

showSlides();

Upvotes: 0

Views: 753

Answers (1)

ariel
ariel

Reputation: 16140

You can do it using css:

.slide {
  transition: opacity 1s ease;
}

For more information check: MDN - Using CSS transitions

And then instead of switching display, you switch opacity:

slides[i].style.opacity = 0; // hide

slides[i].style.opacity = 1; // show

Upvotes: 1

Related Questions