Skip to content

Instantly share code, notes, and snippets.

@Elbone
Created August 14, 2014 04:06
Show Gist options
  • Save Elbone/1bed3661e463f2e06d26 to your computer and use it in GitHub Desktop.
Save Elbone/1bed3661e463f2e06d26 to your computer and use it in GitHub Desktop.
Touch or mouse?
// jQuery touch or pointer class for css
$(document).on('touchstart mouseenter mouseover', function (event) {
var touchOrPointer = 'touch'; // Default
var touchClass = 'now-touch';
var pointerClass = 'now-pointer'
if (event.type == 'touchstart') {
$('body').removeClass(pointerClass).addClass(touchClass);
touchOrPointer = 'touch';
}
else {
$('body').removeClass(touchClass).addClass(pointerClass);
touchOrPointer = 'pointer';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment