Faster clicks on touch devices
On touch devices, click events can take a while to fire - and for users, that often makes your web app feel slow.
Here's a really easy way to mitigate that problem:
var click = !!('ontouchstart' in window) ? 'touchstart' : 'click';
$('#someElement').on(click, function(){...});
Or...
document.addEventListener(click, function(){...}, false);
So, we bind to touchstart for touch devices to make the interactions faster, and fallback to click for non-touch devices.
Written by Kevin Ennis
Related protips
2 Responses
This is beautifully elegant. Well done!
over 1 year ago
·
awesome. just watch out for using it inside scrollable areas :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#