Skip to content

Instantly share code, notes, and snippets.

@yoko
Created December 13, 2008 09:50
Show Gist options
  • Save yoko/35445 to your computer and use it in GitHub Desktop.
Save yoko/35445 to your computer and use it in GitHub Desktop.
マウスオーバーで画像を変更するjQueryプラグイン。ex. $('img.button').roll();
(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