Created
October 11, 2010 15:32
-
-
Save pavenuto/620710 to your computer and use it in GitHub Desktop.
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
$.fn.TouchClass = function(className, options) { | |
var settings = { stick: false }; | |
if (options) $.extend(settings, options); | |
if (typeof(className) == 'undefined') { | |
var className = 'active'; | |
} | |
var downEvent = (window.Touch) ? 'touchstart' : 'mousedown', | |
upEvent = (window.Touch) ? 'touchend' : 'mouseup'; | |
this.bind(downEvent, function(){ | |
$(this).addClass(className); | |
}).bind(upEvent, function(){ | |
if (!settings.stick) { | |
$(this).removeClass(className) | |
} | |
}); | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment