-
I am trying to achieve something similar to Prezi presentation software. Basically having a number of bookmarks to objects on the canvas. When the user goes/jumps between the bookmarks the viewport will 1) pan smoothly to the next object 2) meantime scale the viewport so that the object fits (horizontally or vertically whichever makes the object fit) Is this possible and does anyone already have an example of this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
Is for sure possible, you have 2 tasks, calculating the destination viewport and then animating it. you can use fabric.util.calcScaleToFit to get the zoom level, passing as destination the canvas and source the object.getBoundingRect. I m not entirely sure but a combination of those things will do the trick. |
Beta Was this translation helpful? Give feedback.
-
I needed the exact same thing for my project and this is the only thread i found about this. @rasheed-saqib example was a great start but sadly it offsets all object's its panning into by a small margin. And I also needed a way to automatically zoom into the object, which didnt work well because of the offset. Video Also here's a codesandbox if you want to try it out: https://codesandbox.io/p/sandbox/zk6rrz
|
Beta Was this translation helpful? Give feedback.
Is for sure possible, you have 2 tasks, calculating the destination viewport and then animating it.
To animate a viewport is sufficient to animate the 6 numbers that are part of it.
To calculate the destination viewport, that may be a little effort on your side to understand positioning and geometries.
you can use fabric.util.calcScaleToFit to get the zoom level, passing as destination the canvas and source the object.getBoundingRect.
For the panning, i think the final panning will be something like the object.getCenterPoint() to which you have to subtract half of the canvas dimensions.
I m not entirely sure but a combination of those things will do the trick.