Search code examples
javascriptkonvajs

Is it possible in Konva.js to draw with the left mouse button and drag the stage with the right mouse button?


I'm trying to do an app in which you can draw custom rectangle shape objects and be able to drag your stage at the same time. Is it possible with Konva.js?

var stage = new Konva.Stage({ 
    container: 'container', 
    width: width, 
    height: height 
});

document.addEventListener('mousedown', (e) => { 
    switch (e.button) { 
        case 0: 
            stage.draggable(false); 
            break; 
        case 2: 
            stage.draggable(true); 
        break; 
    } 
});

Solution

  • Ok, so if you wondering how to do it this is a possible solution:

    var stage = new Konva.Stage({ 
        container: 'container', 
        width: width, 
        height: height 
    });
    
    document.addEventListener('mousedown', (e) => { 
        if(e.button === 0) stage.draggable(false); 
    });
    document.addEventListener('mouseup', (e) => { 
        if(e.button === 0) stage.draggable(true); 
    });