Fabricjs pan and zoom

前端 未结 5 1010
陌清茗
陌清茗 2020-12-08 01:40

How can I pan and zoom using fabricjs? I\'ve tried using the methods zoomToPoint and setZoom but they do not work for panning. Once I start using different zoom points I sta

5条回答
  •  情书的邮戳
    2020-12-08 02:05

    I know it is already answered, but I had to do a mouse panning, so I adapted the fiddle of the accepted answer to do so. I post it here for anyone who has to do something like this. This is just the main idea:

    var panning = false;
    canvas.on('mouse:up', function (e) {
        panning = false;
    });
    
    canvas.on('mouse:down', function (e) {
        panning = true;
    });
    canvas.on('mouse:move', function (e) {
        if (panning && e && e.e) {
            var units = 10;
            var delta = new fabric.Point(e.e.movementX, e.e.movementY);
            canvas.relativePan(delta);
        }
    });
    

    Here is the fiddle: http://jsfiddle.net/gncabrera/hkee5L6d/5/

提交回复
热议问题