Skip to content

Instantly share code, notes, and snippets.

@mglaman
Created June 5, 2013 21:17
Show Gist options
  • Save mglaman/5717403 to your computer and use it in GitHub Desktop.
Save mglaman/5717403 to your computer and use it in GitHub Desktop.
Using an element with a background-image, you can specify data-rollover="http://" to specify a rollover image.
$(document).ready(function() {
$('.rollover').each(function() {
var rollover = $(this).data('rollover');
var original = $(this).css('background-image');
$(this).hover(
function() {
$(this).css('background-image', 'url('+rollover+')');
},
function() {
$(this).css('background-image', original);
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment