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

136
Vistas
Onmouseover change image transition

I have the following code snippet to change the src of an img tag when I hover over it.

<img src="./Path/to/image.png" alt="" class="exhibit-banner-img" onmouseover="this.src='./Path/to/newimage.png'" onmouseout="this.src='./Path/to/image.png'">

It runs as expected, but how do I add a transition time to the image when the event is fired? Right now, it changes instantly.

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

0

Please use this code.

.img-container {
  position: relative;
  display: inline-block;
}

.img-container img {
  width: 200px;
  height: 200px;
  vertical-align: middle;
  object-fit: cover;
  transition: all .5s ease;
}

.img-container img:first-child {
  position: relative;
}

.img-container img:last-child {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  opacity: 0;
}

.img-container:hover img:last-child {
  opacity: 1;
}
<span class="img-container">
  <img src="https://www.w3schools.com/html/pic_trulli.jpg">
  <img src="https://www.w3schools.com/html/img_chania.jpg">
</span>

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