Eric
Eric

Reputation: 5101

Pan viewport on touch device

I would like to pan a canvas's viewport on a touch device, I wrote this code:

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

This works well on my desktop PC but not on my smartphone (The viewport is not moving): Do you have an idea why?

Upvotes: 0

Views: 137

Answers (1)

lviggiani
lviggiani

Reputation: 6076

In touch devices, normally you have e.touches[0].clientX instead of e.clientX

Upvotes: 1

Related Questions