0

I have carrusel of photo every foto when it's loaded have the opacity 0 and I wont to make a transiction with opacity 0 to 1

function opacityCarrusel() {
    if (imagenEnsaladas.style.opacity < 1) {
      imagenEnsaladas.style.opacity = +0.1;
    }
  }
  setInterval(opacityCarrusel, 200);

I try that but just it's sum opacity to 0,1 no more

1 Answers1

1

Rewrite that like this

function opacityCarrusel(reset = false) {
    if (typeof opacityCarrusel.opct === "undefined")
       opacityCarrusel.opct = 0;
    if (reset) opacityCarrusel.opct=0;
    if (imagenEnsaladas.style.opacity < 1) {
      opacityCarrusel.opct += 0.1;
      imagenEnsaladas.style.opacity = opacityCarrusel.opct;
    }
  }
setInterval(opacityCarrusel, 200);

And use the reset option when you want to use this function for a new image.