Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
Rewriting this Jquery function as plain Javascript

I'm having some problems rewriting this slideshow function in Javascript. Because of some project constraints, I have to revert back to plain JS.

$(".fadein img:gt(0)").hide();
  setInterval(function() {
    $(".fadein :eq(0)").fadeOut(2000)
      .next().fadeIn(1000)
      .end().appendTo('.fadein');
  }, 240000)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here's a good start for you.

Take a look at: How to do fade-in and fade-out with JavaScript and CSS

And please provide a minimal reproducible example

let fadeInImgElements = document.querySelectorAll('.fadein>img:not(:first-child)');
let fadeInElement = document.querySelector('.fadein:first-child');
const fadeOut = function(element, interval) {
  var op = 1; // initial opacity
  var timer = setInterval(function() {
    if (op <= 0.1) {
      clearInterval(timer);
      element.style.display = 'none';
    }
    element.style.opacity = op;
    element.style.filter = 'alpha(opacity=' + op * 100 + ")";
    op -= op * 0.1;
  }, interval);
}
const fadeIn = function(element, interval) {
  var op = 0.1; // initial opacity
  element.style.display = 'block';
  var timer = setInterval(function() {
    if (op >= 1) {
      clearInterval(timer);
    }
    element.style.opacity = op;
    element.style.filter = 'alpha(opacity=' + op * 100 + ")";
    op += op * 0.1;
  }, interval);
}
fadeInImgElements.forEach(function(img) {
  img.style.display = "none";
})
setInterval(function() {
  fadeOut(fadeInElement, 50);
  fadeIn(fadeInElement.nextElementSibling, 50);
  document.querySelector('.fadein').appendChild(fadeInElement.nextElementSibling);
}, 1000)
<div class="fadein">
  <img alt='fadeInImg' src="https://png.pngtree.com/png-vector/20190406/ourmid/pngtree-img-file-document-icon-png-image_919866.jpg">
  <img alt='fadeInImg' src="https://png.pngtree.com/png-vector/20190406/ourmid/pngtree-img-file-document-icon-png-image_919866.jpg">
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda