Jump to content
GreenSock

Sahil

Uncaught Cannot tween a null target. Draggable bug?

Go to solution Solved by GreenSock,

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 was going through documentation and tried Draggable library and found a possible bug? But seems impossible to stay undetected. I thought I should report it.

 

So if element passed to Draggable doesn't exist it throws error and javascript stops working as well. Are we suppose to make sure element exists and then create Draggable object?

See the Pen meyagj by Sahil89 (@Sahil89) on CodePen

Link to comment
Share on other sites

Generally, yes, it's a bad idea to create a Draggable on an element that doesn't exist. However, I did add some code in the upcoming release that should alleviate this scenario where you pass in selector text that has no results. You can try it out with the [uncompressed] beta version: https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/Draggable-latest-beta.js

  • Like 3
Link to comment
Share on other sites

Clicking on draggable element gives mouse position as zero. Or it depends on different libraries we use to detect click position? Like in this case it is jQuery.

 

See the Pen EVaqqZ by Sahil89 (@Sahil89) on CodePen

Link to comment
Share on other sites

While using static hitTest method, is there way to detect which element is on top? For example, return true only if first element is on top else false?

Link to comment
Share on other sites

  • Solution

As for your pageX/pageY thing, that looks like a problem with jQuery and is completely unrelated to GreenSock code. You can tap into our code like this:

Draggable.create(".draggable", {
    onClick: function(e) {
      console.log("clicked at ", e.pageX, e.pageY);
    }
});

As for determining which element is on top, you could compare the zIndex of the elements. That's not something Draggable does for you in hitTest(). 

  • Like 1
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.
×