tbeseda
3/9/2011 - 11:31 PM

Capture the initial touch event in order to refer to it later during touchmove.

Capture the initial touch event in order to refer to it later during touchmove.

$('#object').live({
  'touchstart': function(e){
     window.firstTouch = e.originalEvent.touches[0].pageX || e.originalEvent.changedTouches[0].pageX;
  },
  'touchmove': function(e){
    e.preventDefault();
    var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
    var elm = $(this).offset();
    var x = touch.pageX - elm.left;
    var y = touch.pageY - elm.top;
    if(x < $(this).width() && x > 0){
      if(y < $(this).height() && y > 0){
        $('#object').scrollLeft($('#object').scrollLeft() + (firstTouch - touch.pageX));
      }
    }
  }
});