Created
December 13, 2008 09:50
-
-
Save yoko/35445 to your computer and use it in GitHub Desktop.
マウスオーバーで画像を変更するjQueryプラグイン。ex. $('img.button').roll();
This file contains 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
(function($) { | |
var options = { | |
suffix: '_o' | |
}; | |
$.rollSetup = function(o) { | |
$.extend(options, o); | |
}; | |
$.fn.roll = function roll() { | |
return this.each(function() { | |
var src = this.src; | |
if (!src) { | |
var target = $('img, input[type="button"]', this); | |
if (target.length) roll.call(target); | |
return; | |
} | |
var out = src; | |
var over = src.replace(/(\.[^.]+$)/, options.suffix+'$1'); | |
$('<img src="'+over+'"/>'); | |
$(this) | |
.mouseenter(function() { this.src = over; }) | |
.mouseleave(function() { this.src = out; }); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment