Skip to content

Instantly share code, notes, and snippets.

@ingowennemaring
Created April 18, 2013 11:34
Show Gist options
  • Save ingowennemaring/5412063 to your computer and use it in GitHub Desktop.
Save ingowennemaring/5412063 to your computer and use it in GitHub Desktop.
Easy image rollover without effects
<img src="http://dummyimage.com/254x403/ccc/000.jpg&amp;text=254x403+-+Produkt" data-hover="http://dummyimage.com/254x403/999/000.jpg&amp;text=254x403+-+Produkt" alt="" />
$('img[data-hover]').each(
function() {
var img = $(this);
// preload hover-image
$('<img />').attr( 'src', img.attr('data-hover') );
// rollover
img.on(
'mouseenter mouseleave',
function() {
var $this = $(this),
orig = $this.attr('src');
$this.attr({
'src': $this.attr('data-hover'),
'data-hover': orig
});
}
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment