Fabric.js: Can't select added object is using zoom/scroll

Created on 5 Mar 2018  路  10Comments  路  Source: fabricjs/fabric.js

Version

2.1.0

Test Case

https://jsfiddle.net/ngbdhkkq/27/

Steps to reproduce

Zoom in canvas using Ctrl+mouse wheel than scroll canvas viewport down using mouse wheel (so image became out of view ) and press "Add img" button.

Expected Behavior

Added image is selectable.

Actual Behavior

Can't select added image...

Also i have an issue with already added objects, after zooming in/out moving they're sometimes also cannot be selected, but i have so steps to reproduce as it acts randomly (when clicking on one object, upper is being selected for example)

All 10 comments

i do not see any bug, till the image is inside the viewport, is selectable properly.

https://www.youtube.com/watch?v=Onh-9zHFWD8
Check video, scroll image out of view with mouse scroll before adding new one.

Checked also in Firefox and IE, issue reproduces in both browsers...

Please help, it works ugly, this is a stopper for me, it works totally randomly, as selection is broken objects are bouncing from time to time when trying to move them, can't select them even when they are in view, helps zooming in/out several times

P.S. It also happens with already added objects not only with added by clicking on button...

Check also this video:
https://youtu.be/hnP8_92ZrS4

This happens because you modify the vieport but you do not call setCoords on the object.
At the end of scrolling or during scrolling, if you modify viewport you have to let fabric recalcuate the new interactive position of the object

So after changing viewport I need to call setCoords for all objects?
obj.setCoords(); without parameters for each object?

Thanks, that worked!

Maybe should add this to core?

No, setCoords is better to be called manually.
If instead of modifying the viewport directly you call setViewport(viewport) , that should happen automatically.

http://fabricjs.com/docs/fabric.StaticCanvas.html#setViewportTransform

Was this page helpful?
0 / 5 - 0 ratings