Skip to content
Advertisement

anime.js animation not working, (the animation doesn’t get initiated)

I just started with anime.js and wrote this basic code, but it doesn’t work.

JavaScript

I had installed anime through npm, and when it didn’t work also included the cdn (line no-6) Can anyone tell where I’m going wrong..?

Advertisement

Answer

Your element does not exist when you execute the document.querySelector statement

Wrap your code in a load event listener

And I also suggest you use addEventListener on the button

JavaScript
JavaScript
JavaScript

When you need more controls, you could delegate:

JavaScript

Here is a more generic version you can study

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement