DavideR
DavideR

Reputation: 570

Swiping a div with jQuery on iPhone

I'd like to swipe a div to the left with jQuery.

I have tried with the swipe method of jQuery Mobile, but I want to really move the div to the left, like the native swipe function of iOS. Can this be done?

Upvotes: 0

Views: 273

Answers (1)

Max Coates
Max Coates

Reputation: 89

Core jQuery doesn't have anything special for touch events, but you can easily build your own using the following events

  • touchstart
  • touchmove
  • touchend
  • touchcancel

For example, the touchmove

document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    var touch = e.touches[0];
    alert(touch.pageX + " - " + touch.pageY);
}, false);

This works in most webkit based browsers (incl. android).

Apple documentation for handling events.

Upvotes: 1

Related Questions