HTML5 Element Touch Events

HTML Element

The touchstart, touchend, touchmove, touchenter, touchleave, touchcancel events must be defined on an element.


Code Example:
<html><head><title>sample</title></head>
  <body>
    <img src="button.png" ontouchstart="alert(event.target)" />
  </body>
</html>
var img = document.createElement('img');
img.ontouchstart=function(e) { 

for(var i = 0; I < e. touches.length; i++)
{
   var touch = touches[i];

   var x = touch.clientX;
   var y = touch.clientY;

   // do something
}
preventMove = function(e) {
   evt.preventDefault();
   window.scroll(0, 0);
   return false;
};
window.document.addEventListener('touchmove', preventMove, false);


Learning Resources:

Reference - Touch API BlackBerry browser JavaScript reference guide [BlackBerry Documentation].
Sample - SketchPad Application Example that draws finger sketches on an HTML5 canvas corresponding to touch screen or trackpad movement [BlackBerry Developer Resource Center].

Supported Platform(s)

- BlackBerry OS 6.0+
- BlackBerry PlayBook 1.0+
- BlackBerry 10
View Supported Platform Table
APIBB5.0BB6.0BB7.0PB1.0PB2.0BB10Ripple
ontouchcancel   Y Y Y Y Y 
ontouchend   Y Y Y Y Y 
ontouchenter   Y Y Y Y Y 
ontouchleave   Y Y Y Y Y 
ontouchmove   Y Y Y Y Y 
ontouchstart   Y Y Y Y Y 

Configuration Document Settings

To use all of the API described for this object, you must ensure the following settings are in your configuration document:

This API does not require a <feature> element to be declared in the configuration document of your BlackBerry WebWorks Application.

Permission Elements (PlayBook and BlackBerry 10+)
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application.

Events

void ontouchcancel (event : TouchEvent)


A user agent must dispatch this event type to indicate when a touch point has been disrupted in an implementation-specific manner, such as a synchronous event or action originating from the UA canceling the touch, or the touch point leaving the document window into a non-document area which is capable of handling user interactions. (e.g. The UA's native user interface, plug-ins) A user agent may also dispatch this event type when the user places more touch points on the touch surface than the device or implementation is configured to store, in which case the earliest Touch object in the TouchList should be removed.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event

void ontouchend (event : TouchEvent)


A user agent must dispatch this event type to indicate when the user removes a touch point from the touch surface, also including cases where the touch point physically leaves the touch surface, such as being dragged off of the screen.

The target of this event must be the same Element that received the touchstart event when this touch point was placed on the surface, even if the touch point has since moved outside the interactive area of the target element.

The touch point or points that were removed must be included in the changedTouches attribute of the TouchEvent, and must not be included in the touches and targetTouches attributes.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event

void ontouchenter (event : TouchEvent)


A user agent must dispatch this event type to indicate when a touch point moves onto the interactive area defined by a DOM element. Events of this type must not bubble.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event

void ontouchleave (event : TouchEvent)


A user agent must dispatch this event type to indicate when a touch point moves off the interactive area defined by a DOM element. Events of this type must not bubble.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event

void ontouchmove (event : TouchEvent)


A user agent must dispatch this event type to indicate when the user moves a touch point along the touch surface.

The target of this event must be the same Element that received the touchstart event when this touch point was placed on the surface, even if the touch point has since moved outside the interactive area of the target element.

If the values of radiusX, radiusY, rotationAngle, or force are known, then the user agent also must dispatch this event type to indicate when any of these attributes of a touch point have changed.

Note that the rate at which the user agent sends touchmove events is implementation-defined, and may depend on hardware capabilities and other implementation details.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event

void ontouchstart (event : TouchEvent)


A user agent must dispatch this event type to indicate when the user places a touch point on the touch surface.

The target of this event must be an Element.


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10


Parameters
event
Documentation generated by JsDoc Toolkit 2.4.0 on Sun Dec 30 2012 18:15:37 GMT-0500 (EST)