0

currently i am using jquery draggable function https://jqueryui.com/draggable/ .

$( ".myclass").draggable({ });

But i want to stop the drag event when the user double click on the dragging element . How to do this ?. Is it [possible to stop dragging in single click ? For some reason my dragging element is come with mouse pointer and i cannot stop dragging .

Thank you .

2
  • i am confused. you drag by holding the left mouse button down. when you let go of the mouse button the element stops being dragged??? Commented Oct 30, 2016 at 6:57
  • Can you please explain a bit better , doubleclick/singleclick how are they supposed to affect the dragging behaviour? Commented Oct 30, 2016 at 7:14

1 Answer 1

1

Draggable should stop automatically when you release your mouse.

HTML

<body>
<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
  <p id="position"></p>
  <p id="event"></p>
</div>
</body>

JS

$( function() {
    $( "#draggable" ).draggable({
      scroll: false,
      drag: function( event, ui ) {
        $('#position').html(
          'Left : ' + ui.position.left + '<br/>' +
          'Top : ' + ui.position.top
        );
      },
      start: function( event, ui ) {
        $('#event').html("Dragging");
      },
      stop: function( event, ui ) {
        $('#event').html("Stopped");
      }
    });
  } );

Try the sample above. The dragstop event is automatically called every time you release your mouse from dragging. Try apply this in your code to further investigate why the dragstop is not being called in your case.

http://codepen.io/jyloo/pen/mrZmjO

Sign up to request clarification or add additional context in comments.

3 Comments

ok . i up voted to this answer . But friend could you please tell how to stop drag on double click .
perhaps you want to try this: $( document ).dblclick(function() { $( ".your-selector" ).draggable( "disable" ); $( ".your-selector" ).draggable( "enable" ); });
hi, could you please check this question stackoverflow.com/questions/40342500/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.