Thank you everyone! What a surprise to be on HN today. Happy to answer questions!
That is a fantastic discussion on dragging with Javascript. Really appreciate the information. I've a quick question. How do you restrict the dragging movement to an axis using the built-in DOM events like dragstart/etc. I had a drag & drop feature implemented using the dragstart/dragenter/dragover/drop/etc events. I couldn't find a quick way to restrict the dragging movement to the x-axis. JQuery's drag and drop API…
1. When I get the event, I update the underlying state, but leave the DOM element alone.
2. I can apply constraints to that state. To restrict dragging to the x-axis, I would never change y.
3. I use the state to drive the redisplay of the DOM element.
Some examples of constraints I want: https://www.redblobgames.com/articles/curved-paths/making-of...
I think jQuery's drag and drop API is using the mouse events directly and not using the built-in dragstart/etc., and that's why they can apply constraints.