question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to manually stop dragging?

See original GitHub issue

How to leave the event if a given condition is reached?

example:

$('#element').draggabilly({
   containment: true,
   axis: 'x'
}).on('dragMove', function() {
   let containerWidth = $(this).parent().width()
   let buttonWidth = $(this).outerWidth()
   let max = (containerWidth - buttonWidth) - 1 // count border right (1px)
   // condiction
   if ( $(this).position().left >= max ) {
       console.log('limit reached')
       return false // escape here!!! don't escaped!
   }
}).on('dragEnd', function() {
   let containerWidth = $(this).parent().width()
   let buttonWidth = $(this).outerWidth()
   let max = (containerWidth - buttonWidth) - 1 // count border right (1px)
   // confirm condiction
   if ( $(this).position().left >= max ) {
       // do stuff...
   } else {
       // do stuff...
   }
}).on('click', function() {
   //...
})

I’m assuming that return on “move” would trigger “end”? Is there a correct method?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
desandrocommented, Jan 12, 2018

Thanks so much for you description and CodePens!

Bad news there is no good API to manually stop dragging. Good news is that you can hack it by calling a private method _pointerUp within dragMove:

var $submitBtn = $('#submit-btn').draggabilly({
   containment: true,
   axis: 'x'
})

var draggie = $submitBtn.data('draggabilly');

$submitBtn.on('dragMove', function( event, pointer ) {
   let containerWidth = $(this).parent().width()
   let buttonWidth = $(this).outerWidth()
   let max = (containerWidth - buttonWidth) - 1 // count border right (1px)
   // condition
   if ( draggie.position.x >= max ) {
       draggie._pointerUp( event.originalEvent, pointer );
   }
})

See demo https://codepen.io/desandro/pen/RxJrra/


Add a 👍 reaction to this issue if you would like to see Draggabilly get a dragStop method added. Do not add +1 comments — They will be deleted.

2reactions
desandrocommented, Dec 29, 2021

Draggabilly v3 has been released with revised dragEnd method. Use it to stop dragging

// jQuery
$draggable.draggabilly('dragEnd')
// vanilla JS
draggie.dragEnd()
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable or disable Drag and Drop in Windows 11/10
To do so, first, create a system restore point or back up the registry. Then open the Registry Editor.
Read more >
d3.js force cancel a drag event - Stack Overflow
Inside the drag event function, you can use mycondition to decide whether or not to update the dragged element's position. Not updating the...
Read more >
How to Disable Dragging of Maximized Windows in Windows 11
Double-click the Disable_drag_maximized_windows.reg file to disable the feature. To undo the change and re-enable the dragging of maximized ...
Read more >
Drag
When you use Drag(Begin!) in a control's Clicked event to manually put the control in drag mode, the user can drag the control...
Read more >
How to Stop Dragging Your Feet and Embrace the Future -
Why Do You Drag Your Feet? 1) You aren't ready to move on. In the summer program where I teach, the kids get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found