You can try this.
8: Touch events
Of course you use your iPhone with a finger instead of a mouse; rather than clicking, you tap. Moreover, you can use several fingers to touch and tap. On iPhone, mouse events are replaced by touch events. It:
touchstarttouchendtouchmovetouchcancel (when the system cancels the touch)
When you subscribe to any of these events, your event listener will receive an event object. The event object has some important properties, for example:
touches - a set of touch objects, one for each finger that touches the screen. Touch objects such as pageX and pageY properties containing the touch coordinates on the page.targetTouches - works like a touch, but only registers the touch of the target element as opposed to the whole page.
The following example is a simple drag and drop implementation. Let's put the box on a blank page and drag it around. All you have to do is subscribe to the touchmove event and update the position of the window as the finger moves, for example:
window.addEventListener('load', function() { var b = document.getElementById('box'), xbox = b.offsetWidth / 2,
The touchmove event touchmove first cancels the default finger behavior, otherwise Safari will scroll the page. The event.targetTouches collection contains a list of data for each finger currently on the target div.
We only care about one finger, so we use event.targetTouches[0] . Then pageX gives us the X coordinate of the finger. From this value, we subtract half the width of the div so that the finger remains in the center of the field.