开发者

How to create viewport in fabric.js

How to create an visible area, a window to a bigger o开发者_如何转开发bject (for creating a scrollable view) using canvas and preferably, using fabric.js


If I understand your question correctly, the easiest approach would be to just create a very large canvas object (larger than your window), and place it inside a parent container. Set the parent container's dimensions equal to the size of your desired window, and then declare overflow: hidden; on the container.

Once that's setup, you can probably use something like jQuery's draggable to handle the mouse events. If that doesn't work, the key idea is that you need to modify the canvas' position attribute, or adjust the margins to simulate panning around the canvas within the window.

This approach of course is intended for finite canvas sizes. If you want to offer an infinite work area, you would probably be better off modifying the context.translate property of your canvas. I imagine this would not play well with fabric.js, however.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜