Jump to content
Search Community

Multiple DropAreas

Rockhopper92 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I've edited one of the codepens provided by Greensock and I've pretty much got what I need (minus the formatting don't judge me!) I'm having trouble though with using multiple dropAreas, I've set up the 15 divs I need as drop areas but can't get the JS to run through them all. I tried copying what was already there and applying the next div variable to it but then it only works for the last one.

 

Probably not explaining this well but you'll see in the javascript I've got dropArea1 which works fine, then dropArea2 later on overrides this so dropArea1 no longer works but dropArea2 does.

See the Pen pdEWME by Rockhopper92 (@Rockhopper92) on CodePen

Edited by Rockhopper92
Wrong codepen link!
Link to comment
Share on other sites

Solved it!

 

    else if (this.hitTest(dropArea2,overlapThreshold)) {
      $(this.target).addClass("highlight");
    }

    else if (this.hitTest(dropArea3,overlapThreshold)) {
      $(this.target).addClass("highlight");
    }

 

...etc. was all that was needed.

  • Like 2
Link to comment
Share on other sites

9 hours ago, Rockhopper92 said:

Solved it!

 

    else if (this.hitTest(dropArea2,overlapThreshold)) {
      $(this.target).addClass("highlight");
    }

    else if (this.hitTest(dropArea3,overlapThreshold)) {
      $(this.target).addClass("highlight");
    }

 

...etc. was all that was needed.

 

You don't need all those else if statements. How about this?

 

See the Pen XzNdoN by osublake (@osublake) on CodePen

 

 

 

  • Like 5
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...