代码之家  ›  专栏  ›  技术社区  ›  Eric

在触摸设备上平移视口

  •  0
  • Eric  · 技术社区  · 7 年前

    我想在触摸设备上平移画布的视口,我编写了以下代码:

    canvas.on('touch:drag', function (opt) {
            var e = opt.e;
            if (this.isDragging) {
                if (e.clientX === undefined ) {
                    this.isDragging = false;
                } else {
                    this.viewportTransform[4] += e.clientX - this.lastPosX;
                    this.viewportTransform[5] += e.clientY - this.lastPosY;
                    this.requestRenderAll();
                    this.lastPosX = e.clientX;
                    this.lastPosY = e.clientY;
                }
            } else {
                this.isDragging = true;
                this.selection = false;
                this.lastPosX = e.clientX;
                this.lastPosY = e.clientY;
            }
        });
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   lviggiani    7 年前

    触控设备,通常 e.touches[0].clientX e.clientX

    推荐文章