Jump to content
Search Community

Doc : camelCase for Draggable.addEventListener()

Cyboide 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

Hi,

 

In the HTML5 doc, Draggable>Methods>addEventListener, it mentions the event strings as camel case, but it is not working for me.

I have to use all small caps.

 

I’m supposed to have the latest 1.17.0.

 

 

Thanks.

Link to comment
Share on other sites

  • 3 months later...

Hi.

 

Getting an error when using Draggable.addEventListener. I have tried both camel case and lowercase. The docs currently say camel case.

 

plugin version: 0.14.1

error: Uncaught TypeError: draggable.addEventListener is not a function

 

When console logging the draggable object I'm not seeing an addEventListener method on the object or it's prototype. Is it still available? 

 

Thanks.

Link to comment
Share on other sites

Here is the exact code from the docs 

 

var myDraggable = Draggable.create("#box1", {
  bounds:"#container"
})[0];


myDraggable.addEventListener("press", onPress);


function onPress() {
  console.log("myDraggable was pressed");
  TweenLite.to(this, 0.2, {backgroundColor:"red"}); // animate the backgroundColor of the target of the Draggable that was pressed
}

 

 

http://codepen.io/GreenSock/pen/vNQeWg?editors=001

 

Seems to work. Are you sure you are using the latest version of Draggable?

  • Like 1
Link to comment
Share on other sites

Draggable.create() is a static method that returns an array of draggable instances. To get something from an array you pass in an index number. 0 would be the first, and in this case, only draggable instance in that array.

 

You could use the get() method to get the instance of your draggable.

Draggable.create("#foo");

var myDraggable = Draggable.get("#foo");

Or you could just create one instance using the constructor.

var myDraggable = new Draggable("#foo");
  • 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.
×
×
  • Create New...