How to manually stop dragging?
See original GitHub issueHow 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:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
withindragMove
: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.Draggabilly v3 has been released with revised
dragEnd
method. Use it to stop dragging