Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda