Jump to content
GreenSock

TopGUN121

Draggable HitTest Get ID of Hit Area

Go to solution Solved by Diaco,

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

Hi everyone,

 

I know i can go about this a different way and make it work but i was still wondering what the answer would be to this questions i have.

 

I'm trying to get the id of the element in the hit test that the target is going over.

 

Ex:

 

 if (this.hitTest("#circle1", "50%")) {        }
 
How would i access and get the value of #circle1 inside the hittest if statement?
 
this.target is the object being dragged, but i want to know what i could use to get the "circle1" value?
 
I'm trying to get html info from that circle1.
 
Thanks!
Brad
Link to comment
Share on other sites

  • Solution

Hi TopGUN121  :)

 

pls try like this :

 

var Targets = document.querySelectorAll('.Targets');

Draggable.create('.Draggable',{
  onDragEnd:function(){
    for(var i=Targets.length; i--{
      if(this.hitTest(Targets[i],'50%')){
         console.log(Targets[i].id)
      }
    }
  }
});
  • 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.
×