In Snap.svg, how to make Element.drag() work only when a particular variable is true

40 Views Asked by At

I have a function like this:-

function dragMap(evt){
  if (mousemode == 'pan'){
    Snap('#zoombox').drag(move, start, stop);
  }
}
dragMap();

My challenge is when variable mousemode changes to something else, e.g. mousemode == 'simple'

even then the following drag code continues to show its effect on dragging Element(#zoombox).

Snap('#zoombox').drag(move, start, stop);

I want that dragging shall work/execute ONLY WHEN variable mousemode is set to 'pan'. What should be way forward?

1

There are 1 best solutions below

1
Ian On BEST ANSWER

Couple of options.

  1. Snap('#zoombox').undrag() whenever mousemode changes.

  2. Write your own drag handler. There's a couple of examples here. Just add a check for your variable inside the functions.