Advertisement
Guest User

TouchList examples

a guest
Jul 19th, 2011
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Example of the relations between different lists.
  3.  */
  4.  
  5. document.getElementById('touchable').addEventListener('touchstart', function(ev) {
  6.    
  7.     if (ev.touches.item(0) == ev.targetTouches.item(0))
  8.     {
  9.         /**
  10.          * If the first touch on the surface is also targeting the
  11.          * "touchable" element, the code below should execute.
  12.          * Since targetTouches is a subset of touches which covers the
  13.          * entire surface, TouchEvent.touches >= TouchEvents.targetTouches
  14.          * is /always/ true.
  15.          */
  16.        
  17.         document.write('Hello Touch Events!');
  18.     }
  19.    
  20.     if (ev.touches.length == ev.targetTouches.length)
  21.     {
  22.         /**
  23.          * If all of the active touch points are on the "touchable"
  24.          * element, the length properties should be the same.
  25.          */
  26.        
  27.         document.write('All points are on target element')
  28.     }
  29.    
  30.     if (ev.touches.length > 1)
  31.     {
  32.         /**
  33.          * On a single touch input device, there can only be one point
  34.          * of contact on the surface, so the following code can only
  35.          * execute when the terminal supports multiple touches.
  36.          */
  37.        
  38.         document.write('Hello Multiple Touch!');
  39.     }
  40.    
  41. }, false);
  42.  
  43. /**
  44.  * Example of changedTouches from a touchend event.
  45.  */
  46.  
  47. document.getElementById('touchable').addEventListener('touchend', function(ev) {
  48.  
  49.     /**
  50.      * Output in a example where three touch points are on the surface, two of
  51.      * them being on the "touchable" element and when the touchend is triggered
  52.      * by lifting one point from "touchable".
  53.      *
  54.      * Touch points removed: 1
  55.      * Touch points left on element: 1
  56.      * Touch points left on document: 2
  57.      */
  58.    
  59.     document.write('Removed: ' + ev.changedTouches.length);
  60.     document.write('Remaining on element: ' + ev.targetTouches.length);
  61.     document.write('Remaining on document: ' + ev.touches.length);
  62.    
  63. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement