Code Snippet
Fade Image Into Another Image
Make a div that is the exact size of the image. This div will have a background image applied to it of the second image. Then put an inline image inside it.
<div id="kitten">
<img src="/images/kitten.jpg" alt="Kitten" />
</div>Fading the inline image in and out will reveal/hide the second (background) image.
$("#kitten").hover(function(){
$(this).find("img").fadeOut();
}, function() {
$(this).find("img").fadeIn();
});
nice effect thank for sharing.
fadeIn() is not called until after fadeOut has returned, so although simple, it visually leaves alot of room for improvement.
This is horrible. It fades out the first and THEN fadeIn the other one.
You re not doing what you’re saying: fade one image INTO another.
Did you even read the post? The containing DIV has a background image equal to the second image. When you hover over the IMG element, it fades out, displaying the 2nd image (in the form of the container DIV and its BG image). When you mouse-out, the IMG fades back in, covering up the container DIV background, and displaying the first image (IMG element) once again.
Thanks, It is very useful
it doesn’t work , any help plz?
and i want something like you do in the “PROPS” in This Page …. thanx
Cool :)
I’m gonna be using this on my site, thanks :)
Ashley
It’s worth noting that using
.fadeOut()and.fadeIn(), the element will be set todisplay: none;, losing its dimensions. It’s worth just changing the opacity if you’re fading it:$("#kitten").hover(function(){$(this).find("img").animate({opacity: 0}, 500);
}, function() {
$(this).find("img").animate({opacity: 1}, 500);
});
This is what I needed…except I needed it to work on multiple images so I couldn’t use an ID, and I needed the
divto not disappear when hovered on. With the help of @visualidiot on Forrst this is the solution that was contrived:<div class="fade">
<img src="/images/kitten.jpg" alt="Kitten" />
</div>
$(".fade").hover(function(){
$(this).find("img").stop(true,true).animate({opacity: 0}, 400);
}, function() {
$(this).find("img").stop(true,true).animate({opacity: 1}, 400);
});
To increase or decrease the fade time adjust 400 to whatever value suits you (higher is longer, lower is faster).
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.