Cross Fade

Cross Fade

 

 

Using CSS Transitions to Create Cross Fading Images

Changing one image to another on mouse hover.

Example

 
 

HTML Markup

 

<div id="crossfade">
  <img class="bottom" src="/images/photo1.jpg" />
  <img class="top" src="/images/photo2.jpg" />
</div>

 

CSS

 

#crossfade {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto;
}

#crossfade img {
  position:absolute;
  left:0;
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
}

#crossfade img, top:hover {
  opacity:0;
}