Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

What's wrong with this code?

I'm using Tumult Hype which is an HTML 5 animation tool, and I want to create a drag and drop element that when dropped into another element initiates an animation.

I've followed instructions from this page: http://tumult.com/hype/documentation/javascript/

And have come up with the following code which for some reason isn't working:

function dragdrop(hypeDocument, element, event) { var drag = hypeDocument.getElementById('drag') var drop = hypeDocument.getElementById('drop')

if (event['hypeGesturePhase'] == hypeDocument.kHypeGesturePhaseMove) {

if (drag.offsetLeft > drop.offsetLeft && drag.offsetTop > drop.offsetTop && drag.offsetLeft + drag.offsetWidth < drop.offsetLeft + drop.offsetWidth && drag.offsetTop + drag.offsetHeight < drop.offsetTop + drop.offsetHeight) {
hypeDocument.startTimelineNamed('Ani');
} 

}

The variables were created using Unique Element IDs within the Hype document which I have checked multiple times and are correct. And the timeline that I wish to start once the drag element has been dropped into the drop element is called 'Ani' which you can see in the third to last line of code.

I'm very new to Javascript and am struggling to get to grips with it so would appreciate any help anyone can provide.

Thanks!

Jamie