Created
March 22, 2010 20:47
-
-
Save anotheremily/340512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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