Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anotheremily/340512 to your computer and use it in GitHub Desktop.
Save anotheremily/340512 to your computer and use it in GitHub Desktop.
/**
* Creates rollover functionality in JavaScript
* requires JQuery
* Rollovers should by default have their off state as the
* original image src. Set the on and off markers with the
* variables on the first two lines. By default they are
* _on and _off (i.e. rollover_off.jpg, rollover_on.jpg.)
*/
function createRollovers() {
var onText = "_on",
offText = "_off";
$('img.rollover' ).each( function() {
var onImg = $(this).attr('src').replace(offText,onText),
offImg = $(this).attr('src').replace(onText,offText);
$(this).bind('mouseenter', function () {
$(this).attr('src', onImg );
});
$(this).bind('mouseleave', function () {
$(this).attr('src', offImg );
});
});
return;
}
$(document).ready(function () {
createRollovers();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment