添加到Benicks答案 - 你可以调用当对象移动时触发canvas.on("object:moving", function(e) {})
。所以包装将有follwing CSS:
#wrapper{
position: absolute;
overflow: auto;
max-height: 600px;
max-width: 800px;
}
与索引文件:
<div id="wrapper">
<canvas id="c2"></canvas>
</div>
要扩展画布作为一个对象被拖动到你可以做以下包装的边缘(已完成在咖啡脚本中):
canvas.on "object:moving", (e) ->
currentCanvasHeight = canvas.height
currentCanvasWidth = canvas.width
# e.target returns the selected canvas object
# Once the objects offset left value + the objects width is greater than the canvas
# width, expand the canvas width
if (e.target.left + e.target.currentWidth) > currentCanvasWidth
canvas.setWidth currentCanvasWidth + 50
$("#wrapper").scrollLeft e.target.left # scroll alongside the canvas expansion
$('#wrapper').on 'scroll', canvas.calcOffset.bind(canvas) # to fix the mouse
#position bug issue
# do the same for the top
if (e.target.top + e.target.currentHeight) > currentCanvasHeight
canvas.setHeight currentCanvasHeight + 50
$("#wrapper").scrollTop e.target.top
$('#wrapper').on 'scroll', canvas.calcOffset.bind(canvas)
刚才编辑的答案,谢谢Promethean_Sin –
但所有的浏览器(不fabricjs)对画布大小的限制,所以我觉得'canvas.setWidth/setHeight'的通话最终将失败:https://开头github上。 COM/kangax/fabric.js /问题/ 3821 – Smartkid