Skip to content

Instantly share code, notes, and snippets.

@ingowennemaring
Last active December 16, 2015 09:28
Show Gist options
  • Save ingowennemaring/5412678 to your computer and use it in GitHub Desktop.
Save ingowennemaring/5412678 to your computer and use it in GitHub Desktop.
Image Rollover with CSS, fade effect and image preload
figure {
display: inline-block;
position: relative;
margin: 0;
padding: 0;
img {
display: block;
&:last-child {
position: absolute;
top: 0;
left: 0;
opacity: 0;
-webkit-transition: opacity 1s;
-moz-transition: opacity 1s;
-ms-transition: opacity 1s;
-o-transition: opacity 1s;
transition: opacity 1s;
}
}
&:hover img:last-child {
opacity: 1;
}
}
<figure>
<img src="http://dummyimage.com/254x403/ccc/000.jpg&amp;text=254x403+-+Produkt" alt="" data-hover="http://dummyimage.com/254x403/999/000.jpg&amp;text=254x403+-+Produkt" />
</figure>
$('img[data-hover]').each(
function() {
var img = $(this);
$('<img />')
.attr( 'src', img.data('hover') )
.appendTo( img.parent() );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment