在捏手势上缩放图像

pau*_*ith 5 html mobile jquery touch pinch

我正在使用jQuery touchy插件来检测pinch事件,以便用户能够放大/缩小图像.这是我的代码的要点:

var w = 800,
    h = 600;
$('img').on('touchy-pinch', function (e, $target, data) {
    $(this).css({
        width: w * data.scale,
        height: h * data.scale
    });
});

自定义数据对象包含以下内容:

  • 规模
  • previousScale
  • 当前点
  • 起点
  • startDistance

它在第一次捏合时工作正常,但是一旦我的手指离开屏幕,然后我再次尝试再做,图像会重新缩放.如何修改我的处理程序,以便图像从中断处继续而不是重新缩放?使用数据的previousScale并没有帮助,因为之前的Scale也会被重置.