Skip to content

Instantly share code, notes, and snippets.

@pavenuto
Created October 11, 2010 15:32
Show Gist options
  • Save pavenuto/620710 to your computer and use it in GitHub Desktop.
Save pavenuto/620710 to your computer and use it in GitHub Desktop.
$.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