Jump to content
Search Community

How to troubleshoot a Hit Test error in Draggable.js

solomania9 test
Moderator Tag

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

This chunk of code was working great in one JS file, but now I'm using the code in another project and it's giving me this error in Chrome:

Draggable.js:2186 Uncaught TypeError: _unwrapElement(...).getBoundingClientRect is not a function

 

The line in my code that's triggering the error is the line below, "if (this.hitTest..."

function onDrag() {
    G.hitting = null;
    tile.positioned = false;
    for (var i = 0; i < G.tiles.length; i++) {
        if (this.hitTest(G.tiles[i], G.dragThreshhold)) {
            G.hitting = i;
        }
    }
    console.log("currently hitting "+G.hitting);
}

How do I go about troubleshooting this? I'm sure the error isn't actually in Draggable.js, but instead it has something to do with how my code is set up. FWIW, the code chunk in the broken page is identical to the code in the working page.

 

I've tried changing the order the JS scrips that are being loaded on the page, but no luck.

 

What are some other things I can try to troubleshoot this?

 

Link to comment
Share on other sites

  • Solution

Sounds like G.tiles is spitting back something that's not valid. Are you sure it's a DOM element? Maybe add a console.log(G.tiles) just above that line to see what's being returned. Tough to troubleshoot blind - if you provide a reduced test case in codepen, we'd be happy to take a peek. 

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