Skip to content

Instantly share code, notes, and snippets.

@yonestra
Created November 10, 2012 07:40
Show Gist options
  • Save yonestra/4050318 to your computer and use it in GitHub Desktop.
Save yonestra/4050318 to your computer and use it in GitHub Desktop.
Drag view on Titanium mobile.
var counter = 1;
var startX = null, startY = null;
view.addEventListener('touchstart', function(e){
startX = e.x, startY = e.y;
});
view.addEventListener('touchmove', function(e){
if((counter % 5) == 0){
var x = (e.x - startX) + view.animatedCenter.x;
var y = (e.y - startY) + view.animatedCenter.y;
view.animate({top:y-viewHeight/2, left:x-viewHeight/2, duration:1});
counter = 0;
}
counter += 1;
});
view.addEventListener('touchend', function(e){
startX = null, startY = null;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment