Skip to content
Advertisement

Stop drag event when reaching the min or max

How can I stop dragging as soon as the drag hits top and bottom of the .parent?

As you can see the .button is stops as soon as it hits the inner top and bottom of the .parent but the event still continuing! . to test it try to drag the .button to the bottom ot top and do not stop dragging when reaching the end, as you can see the new_top still updating!

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You can add this line inside your check:

JavaScript

Which removes the mousemove listener when you hit the max y position.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement