Guest User

Untitled

a guest
Jan 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. I know that you can get and respond to touch details with the event.touched method.
  2. You could call an if statement on this method to take different action dependent on the extend of finger movement.
  3. For example, using event.changedTouches[0] inside a touchstart event listener and measuring that against
  4. event.changedTouches[0] in a 'touchend' event listener. However, I am not certain how to implement that as I do not
  5. have a touchscreen laptop so I cant experiment with the Javascripts touch event methods
  6. (cancel, end, move or start). Therefore, knowing what I do know I would try these approaches...
  7.  
  8.  
  9. 1. You could change 'touchstart' (which fires on screen pressdown) to 'click' so that the function only fires on click
  10. behavior(which would need a 'finger down then finger up' action to work).
  11. I would also put in event.preventDefault() to stop default form submission behavior...
  12.  
  13. $(function(){
  14. $(document).on("click", "#start", (event) => {
  15. event.PreventDefault();
  16. console && console.log("we think the user pressed a button but might have just started a scroll from the button");
  17. });
  18. });
  19.  
  20.  
  21. 2. This function tests for the length of the touchstart. You could then make different choices
  22. depending on whether the finger touch was more than 400 milliseconds...
  23.  
  24. (function() {
  25. var long = 4000;
  26. var start;
  27. $( "#start" ).on( 'mousedown', function( e ) {
  28. go = new Date().getTime();
  29. } );
  30.  
  31. $( "#start" ).on( 'mouseleave', function( e ) {
  32. go = 0;
  33. } );
  34.  
  35. $( "#start" ).on( 'mouseup', function( e ) {
  36. if ( new Date().getTime() >= ( go + long ) ) {
  37. console.log('trigger scrolling behaviour here');
  38. } else {
  39. console.log('trigger click button behaviour');
  40. }
  41. } );
  42. }());
Add Comment
Please, Sign In to add comment