'"Disable" panning when the zoom is below a specific level in cytoscape.js

I would like to "disable" panning by the user, when the zoom is below a specific level. I tried:

I tried using cy.panningEnabled(false) but it also disable the zoom. (I just want to prevent panning but let the user being able to zoom).

I thought about doing this with a return in on("pan") event:

    cy.on('pan', function (evt) { // don't allow panning 
        if (cy.zoom() < 1.5) {            
            console.log("Dont allow panning");
            return;
        }
    });

But it doesn't work, the panning action is still executed.

Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source