我正在为我的应用程序使用Hammers库。如何从触摸的任何点而不是居中地拖动元素?谢谢 !

var hammertime = Hammer(document.getElementById('contentTab'), {
    transform_always_block:true,
    transform_min_scale: 1,
   drag_block_horizontal: true,
    drag_block_vertical: true,
    drag_min_distance: 0,
    drag_max_touches: 2,
    release: false

});

var rect = document.getElementById('tabella');

var posX=0, posY=0,
    scale=1, last_scale,
    rotation= 1, last_rotation,
    dt =0;

hammertime.on('touch  doubletap drag transform', function(ev) {
    switch(ev.type) {

    case 'doubletap':
        if (dt == 0){
            dt=1;
            scale = 2;
        }else if (dt ==1){
            dt = 0;
            scale = 1;
            posX=0;
            posY=0;
        }

      last_rotation = rotation;
        break;

        case 'touch':
            last_scale = scale;

          last_rotation = rotation;
            break;



     case 'drag':



          posX = ev.gesture.deltaX;
            posY = ev.gesture.deltaY;
            break;

        case 'transform':
   //         rotation = last_rotation + ev.gesture.rotation;
            scale = Math.max(1, Math.min(last_scale * ev.gesture.scale, 10));
            break;
    }

    // transform!
    var transform =
            "translate3d("+posX+"px,"+posY+"px, 0) " +
            "scale3d("+scale+","+scale+", 0) " ;
            "rotate("+rotation+"deg) ";

    rect.style.transform = transform;
    rect.style.oTransform = transform;
    rect.style.msTransform = transform;
    rect.style.mozTransform = transform;
    rect.style.webkitTransform = transform;
});

最佳答案

改变中

posX = ev.gesture.deltaX;
posY = ev.gesture.deltaY;




posX += ev.gesture.deltaX;
posY += ev.gesture.deltaY;


可能会解决问题。

关于javascript - 锤阻力中心,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15222264/

10-12 06:51