Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Created March 9, 2011 23:31
Show Gist options
  • Save tbeseda/863243 to your computer and use it in GitHub Desktop.
Save tbeseda/863243 to your computer and use it in GitHub Desktop.
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));
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment