LoginSignup
4
4

More than 5 years have passed since last update.

TitaniumでViewをdragする

Posted at

この記事を参考に、動くように改良。

js
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;
});

e.x, e.yで取れるのはviewからの相対的な位置のようなので、最初にtouchした時点の位置を覚えておき差分を動かすように修正。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4