fabricjs-viewport icon indicating copy to clipboard operation
fabricjs-viewport copied to clipboard

wrong selection origin in chrome

Open Anisotropic opened this issue 11 years ago • 4 comments

In chrome 36 try load demo, doing some zoomin, then hit f12 - developers panel opens, do some mousewheel tap to bottom of page. And now click and drag over canvas = selection are drawing higher then must be.

Anisotropic avatar Aug 27 '14 10:08 Anisotropic

Happens also on Windows Edge and on Firefox...

Any solution?

Raggaer avatar Aug 16 '15 17:08 Raggaer

Same issue here. Even in the Demo.

slow-loris avatar Aug 19 '15 12:08 slow-loris

I did not see it mentioned anywhere else, but the selection origin is wrong simply by scrolling the page down on the browser. Apparently selection is based on absolute positioning instead of relative positioning of the <canvas>.

Is there a solution, or just turn scrolling off?

You can duplicate this on the DEMO by adjusting the browser height to be shorter than the canvas, then scrolling down a little, then try and select the object.

Perhaps related... I am interested in knowing how to force the fabric-viewport canvas to always fill absolute 100% height and width (dynamic when browser is resized) and thus avoid the scrolling problem. Any suggestions?

deenfoxx avatar Nov 01 '15 15:11 deenfoxx

@deenfoxx I had the same issue, and fixed by using pageX/pageY instead of clientX/clientY in the transformEventParams function. This is the working code:

Viewport.prototype._transformEventParams = function (e) {
    var offsetLeft, offsetTop;
    offsetTop = this.canvas.wrapperEl.getBoundingClientRect().top;
    offsetLeft = this.canvas.wrapperEl.getBoundingClientRect().left;
    return {
        which: 1,
        shiftKey: e.shiftKey, //This fixes the multiple selection while pressing shift
        clientX: (e.pageX - offsetLeft) / this.zoom + offsetLeft - this.translate().x, //Using e.pageX instead of e.clientX
        clientY: (e.pageY - offsetTop) / this.zoom + offsetTop - this.translate().y,//Using e.pageY instead of e.clientY
        pageX: e.pageX - this.translate().x,
        pageY: e.pageY - this.translate().y,
        screenX: e.screenX - this.translate().x,
        screenY: e.screenY - this.translate().y
    };
};

dBiazioli avatar Nov 11 '15 13:11 dBiazioli