Skip to content

Instantly share code, notes, and snippets.

@gsharp
Created May 19, 2009 20:47
Show Gist options
  • Save gsharp/114390 to your computer and use it in GitHub Desktop.
Save gsharp/114390 to your computer and use it in GitHub Desktop.
jQuery(document).ready( function() {
// this will run after page load
DUDE.rollover.init();
});
// creates DUDE hash/object
DUDE = {};
// Setup DUDE.rollover child object expando
// DUDE.rollover becomes the main object context
DUDE.rollover = {
/* defins DUDE.rollover.init()
- the init is called after the page loads!!!
by then the other functions below have been set into memory
otherwise this function would depend on functions that hasn't been parsed yet
*/
init: function() {
this.preload();
jQuery(".ro").hover(
// over
function () { jQuery(this).attr( 'src', DUDE.rollover.newimage(jQuery(this).attr('src')) ); },
// out
function () { jQuery(this).attr( 'src', DUDE.rollover.oldimage(jQuery(this).attr('src')) ); }
);
},
// defines DUDE.rollover.preload() function
preload: function() {
jQuery(window).bind('load', function() {
jQuery('.ro').each( function( key, elm ) { jQuery('<img>').attr( 'src', DUDE.rollover.newimage( jQuery(this).attr('src') ) ); });
});
},
// defines DUDE.rollover.newimage() function
newimage: function( src ){ return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_o' + src.match(/(\.[a-z]+)/)[0]; },
// defines DUDE.rollover.oldimage() function
oldimage: function( src ){ return src.replace(/_o/, ''); }
};// ends DUDE.rollover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment