Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created December 20, 2010 09:34
Show Gist options
  • Save hokaccha/748198 to your computer and use it in GitHub Desktop.
Save hokaccha/748198 to your computer and use it in GitHub Desktop.
// iPhoneとかでtap時に画像を切り替える
// demo: http://dl.dropbox.com/u/336104/demo/iphone_tap/index.html
// Usage:
// $('.btn').tapactive();
$.fn.tapactive = function(opt) {
opt = $.extend({
suffix: "_o"
}, opt);
return this.each(function() {
var $elem = $(this);
var src = $elem.attr("src");
var src_o = src.replace(/(.*)\.(.*)$/, "$1" + opt.suffix + ".$2");
(new Image).src = src_o;
$elem.bind("mousedown touchstart", function() {
$elem.attr("src", src_o);
});
$elem.bind("mouseup touchend", function() {
$elem.attr("src", src);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment