Help us understand the problem. What is going on with this article?


More than 5 years have passed since last update.


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した時点の位置を覚えておき差分を動かすように修正。

累計7000万DL超のスマホアプリを自社企画・開発 ツール系からマンガ、ゲームなど幅広いジャンルのアプリを展開
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away