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

255
Vistas
How do I get this jQuery fade in function working?

I'm trying to get this background image to fade in when the page loads.

I've tried selecting the image by class and used the fadeIn() method but nothing is happening when loading the screen?

Am I missing something?

// document.ready(alert("Welcome!"));

$(".background").ready(function () {
  $(".background").fadeIn("slow");
});

Above is the jQuery I've been trying.

And here is the html for reference:

<body>
    <img class="background" src="restaurant.jpg" />
</body>
   
  

Thanks! Im also brand new to jQuery just learning..

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

// Alternative to load event
    document.onreadystatechange = function () {
      if (document.readyState === 'complete') {
    alert('Dom loaded');
        $(".download").fadeIn();
      }
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src='https://www.w3schools.com/images/compatible_chrome.png' class='download' style='display:none;'>

First hide the image then Try the below code which executes once dom loaded.

// Alternative to load event
document.onreadystatechange = function () {
  if (document.readyState === 'complete') {
    console.log('loaded');
    $(".background").fadeIn("slow");
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to set your image display: none; initially

<img class="background" src="restaurant.jpg" style="display: none;"/>

And then you can call this in your Javascript

$(".background").ready(function () {
  $(".background").fadeIn("slow");
});

Or like this

$(document).ready(function() {
  $(".background").fadeIn("slow");
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

  1. set display none
  2. Set milliseconds timeout in fadeIn.

$(document).ready(function() {
  $('.background').css("display", "none").fadeIn(5000); // 5 Second
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class="background" src="https://picsum.photos/200/300"/>

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