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

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

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 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!