Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Vincentccw

Animation not playing

Recommended Posts

Just a quick question, I've created a simple list menu, when I click the "click here" text it is suppose to make all the child list to animate from left to right. However I get

Uncaught TypeError: Cannot call method 'play' of undefined 

Here is my pen:

See the Pen dCpok by vincentccw (@vincentccw) on CodePen

 

Thanks for the help.

Link to comment
Share on other sites

Hi, it is a generally bad idea to store data in DOM/jQuery elements. Why don't you do

See the Pen KLvCi by bassta (@bassta) on CodePen

instead? 

Link to comment
Share on other sites

You added the animation property to the DOM element, but tried to access it from the jQuery collection (which is an array containing DOM elements). You're looking for:

$(".as").prop('animation').play();
// or
$(".as")[0].animation.play();

Also Chrysto, why do you think it's a bad idea to store the data there? Any namespace issues exist at the global window level as well, and I can't think of any other downsides.

Link to comment
Share on other sites

Hi, it is a generally bad idea to store data in DOM/jQuery elements. Why don't you do

See the Pen KLvCi by bassta (@bassta) on CodePen

instead? 

Thanks for the solution, however I'm trying to animate the button individually.

 

If I use your method, I don't think I can workaround it

 

here is the revised pen:

See the Pen aiBjy by vincentccw (@vincentccw) on CodePen

Link to comment
Share on other sites

Hi,

 

Here is what I would do: 

See the Pen fxKyD by bassta (@bassta) on CodePen

As Jamie pointed, the problem is that you're assigning the animation to the original DOM object, which you can get with $selector[0] or $selector.get(0)

 

@Jamie, in some cases it can have impact on performance and also gets very messy with scoping. Most of the times there's a better way to accomplish the same results. 

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.
×