Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!