在触摸设备上泛视口

问题描述 投票:0回答:1

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

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

这适用于我的台式机,但不适用于我的智能手机(视口不动):你知道为什么吗?

javascript fabricjs
1个回答
1
投票

在触摸设备中,通常你有e.touches[0].clientX而不是e.clientX

© www.soinside.com 2019 - 2024. All rights reserved.