transition background-image/css change on hover?
Posted
by John Isaacks
on Stack Overflow
See other posts from Stack Overflow
or by John Isaacks
Published on 2010-06-01T19:56:09Z
Indexed on
2010/06/01
20:03 UTC
Read the original article
Hit count: 161
JavaScript
|jQuery
I have a thumb nail inside another div, when the thumbnail is hovered I want the parent div to fade/transition to the background of the thumbnail, then fade back to the original image after hover.
I have this so far which changes the parent background to that of the thumbnail and back but with no transition.
$(document).ready(function() {
var originalBG;
var hoverBG;
$(".alt-img").hover(
function () {
originalBG = $(this).parent().css('backgroundImage');
hoverBG = $(this).css('backgroundImage');
$(this).parent().css('backgroundImage',hoverBG);
},
function () {
$(this).parent().css('backgroundImage',originalBG);
}
);
});
© Stack Overflow or respective owner