2

The problem is quite simple, take a look at this

$("#element").draggable({
    axis: "x",
    drag: function(event, obj){
        if(condition)
            return false;
    }
});

As you can see if condition is true dragging will be stopped and it won't be possible to continue dragging to any direction unless mouse key is released and pressed again.

So the question is how can I stop user dragging element to some direction without stopping drag to any other directions?

Linas
  • 4,380
  • 17
  • 69
  • 117
  • do you need to restrict the drag axis? – Nouphal.M Jan 03 '14 at 08:59
  • @Nouphal.M Yes i do, but in my situation containment option will not work. I have everything working but the fact that once any of the conditions are true and draggig is stopped until users releases mouse and tries to drag again to the other side is really annoying. – Linas Jan 03 '14 at 09:03
  • Please check this fiddle http://jsfiddle.net/NFY7m/. i cannot really understand your problem here – Nouphal.M Jan 03 '14 at 09:08
  • @Nouphal.M Take a look at this im sure you will understand what i meant. http://jsfiddle.net/NFY7m/1/ – Linas Jan 03 '14 at 09:14

1 Answers1

4

Try this, just reset back the position to 0.

$(function() {
    $( "#draggable" ).draggable({ 
        axis: "y",
        drag: function(event, obj){
            if(obj.position.top > 0){
               obj.position.top = 0;
            }
        },

    });

 });

See demo here

Nouphal.M
  • 6,304
  • 1
  • 17
  • 28