Love this. I was just implementing dragging an SVG element in a Vue app earlier this week, and had to discover pretty much everything the author describes in the article, even in the same order the author describes them, and ended up with pretty much an identical component to do so (except I wrote a composable utility `useDragging` instead of a functional component ` `).
Cool! I've tried a directive and tried a component (with slots) but I haven't tried a composable, mainly because I wasn't sure how to set up event handlers that way. (I don't have a lot of experience with composables)
Draggable objects
131–140 of 147 posts
Re: Draggable objects
#132Earlier quoted context omitted.
Oof, or drag-to-reorder while supporting nesting.
I've always been surprised that Apple added this functionality to the iOS home screen without having a solution to the reorder vs nesting UI problem. Trying to move an app into a folder often results in the folder deciding to fly out of the way and let the item take its place when you're really trying to drop something on the folder to insert it.
Re: Draggable objects
#133Earlier quoted context omitted.
What’s the rationale here?
Having separate code paths for "it's a press", "it's a release", "it's a drag" just turns into a nightmare when you actually use all 3 input events extensively. Remember that while the motion events of the drag might be the visually interesting part, for the most part the interesting stuff happens at the beginning and end of them - i.e. the press and release. It becomes massively simpler conceptually (and even in the…
Re: Draggable objects
#134Earlier quoted context omitted.
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…
I don't know how to do that with the built-in drag-and-drop API. With mouse or pointer events: 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/artic…
Re: Draggable objects
#135Earlier quoted context omitted.
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…
Unfortunately you can’t. That (draggable) API is not designed with that use case in mind.
Re: Draggable objects
#136Earlier quoted context omitted.
I was bored so I made a super simple implementation of this: https://codepen.io/Nezteb/pen/MWZBapL
I thought they meant the object automatically snaps to the nearest target in real-time.
Re: Draggable objects
#137Earlier quoted context omitted.
I was bored so I made a super simple implementation of this: https://codepen.io/Nezteb/pen/MWZBapL
Doesn't work with touch.
Re: Draggable objects
#138Earlier quoted context omitted.
I was bored so I made a super simple implementation of this: https://codepen.io/Nezteb/pen/MWZBapL
That doesn't seem to work in Firefox: > TypeError: input.getBoundingClientRect is not a function
Re: Draggable objects
#139Earlier quoted context omitted.
"If you’re in the Silicon Valley area and want to chat in person, email me at redblobgames@gmail.com. "
Context: I had been planning to visit adanto6840 on a road trip planned for March 2020, but then … the pandemic hit and I had to cancel those plans. But one day I will take that road trip :-)