Jump to content
Search Community

Drag and Drop with Draggable, keeping dropped items aligned with content on viewport resize

jamesstephensaul test
Moderator Tag

Recommended Posts

Hi there,

 

I'm working on a drag and drop interface where dropped elements align to areas on a grid.  

 

My issue is that currently when the viewport is resized, the dropped elements become misaligned with the grid area.    I've experimented with adding a ResizeObserver to trigger a change when the screen is resized but I've not yet been able to figure out how to update the dropped icons so that they move relative to the viewport.  Is there a recommended way to do this with GSAP?  

Any tips much appreciated

See the Pen JjxPjvP by jimmys (@jimmys) on CodePen

Link to comment
Share on other sites

Hi,

 

I think the best way here is to reparent the element being dragged and be done with it.

 

Here is a simple example illustrating that and how this works regardless of the screen width:

https://stackblitz.com/edit/stackblitz-starters-6fdfv3?description=GSAP with Vue&file=src%2FApp.vue&title=GSAP Starter

 

It sure does need some tinkering and I'd definitely would use conditional rendering using v-if, but I'll leave that to you.

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...