javascript - How to detect more then 2 second the touchscreen was pressed? -
using google chrome , canary.
how detect more 2 second touchscreen pressed? (with mouse works real-touch screen failing, tested on surface pro 3)
$(document).ready(function() { var clickstart; var clickstop; $(document).bind('contextmenu', function() { console.log('touch screen, has no right click.'); return false; }); $(document).mousedown( function() { return false; }); // usb mouse pointer works, real-touch screen not working $('#vip_anytime').on('mousedown', function(e) { clickstart = e.timestamp; }).on('mouseup', function(e) { clickstop = e.timestamp- clickstart; if(clickstop >= 2000) { console.log('>>> after 2 second of hold'); } else { console.log('>>> before 2 second of hold'); } }); });
try touchstart
, touchend
events.
$('#vip_anytime').on('touchstart', function(e) { clickstart = e.timestamp; }).on('touchend', function(e) { clickstop = e.timestamp- clickstart; if(clickstop >= 2000) { console.log('>>> after 2 second of hold'); } else { console.log('>>> before 2 second of hold'); } });
Comments
Post a Comment