Skip to content

Instantly share code, notes, and snippets.

@ncou
Forked from c3ry5/detect-touch.js
Created January 5, 2017 01:22
Show Gist options
  • Select an option

  • Save ncou/9219fcf32b710cfe3a52453c692c2053 to your computer and use it in GitHub Desktop.

Select an option

Save ncou/9219fcf32b710cfe3a52453c692c2053 to your computer and use it in GitHub Desktop.
To detect if i device supports touch events with a jquery scroll function
var isTouch = function () {
return 'ontouchend' in document;
}
/* unbind first to prevent double binding of action */
$(window).unbind(isTouch() ? 'touchmove' : 'scroll');
$(window).bind(isTouch() ? 'touchmove' : 'scroll', function(){
/*callback function*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment