Delaying an Edge Animate asset until visible

Here’s a simple little modification that may be useful for people using Edge Animate. The default behavior for an Edge Animate animation is to play immediately. You can disable this of course and use the JavaScript API to play whenever you want. Here’s an interesting use for this. What if your Edge Animate asset is on a page where it may not be visible? For example, a page with lots of text or other assets above it? Here is how I solved it.

First, ensure you disable autoplay on the Stage element:

Next, click on the “Open Actions” panel and enter some text for the creationComplete event. I don’t write much JavaScript directly in Edge Animate, instead, I simply put in something simple, like console.log(‘yo mama!’), just to get Edge Animate to create the event and make it easier for me to find in my editor.

I created a simple application, ran the code, and ensured that it was not running (since I had disabled autoplay). Now for the fun part. How do we tell if we the Edge Animate asset is visible? I turned to Stack Overflow and found a great utility for this (well, for DOM items in general): Check if element is visible after scrolling As you can see, it checks the Window’s current scroll setting as well as the DOM item’s size.

Given this function, I decided on this basic pseudo-code:

if(visible) run the animation
else listen for scroll events and check if visible

Here is the code I came up with:

You can try a demo of this here: Please try not to be too amazed at my incredible animation and design skills.

  • A

    I´m new in this stuff

    And it doesn’t work for me
    Where should I place this code?

    And does it work with multiple animations?

    • http://www.raymondcamdencom/ Raymond Camden

      Did you read carefully? The post tells you where to put the code in.

  • Giulianna Trivellato

    I tried everything but it still doesn’t work…. what I might be forgetting? could you post the exemple files?

    • http://www.raymondcamdencom/ Raymond Camden

      They are posted at the URL towards the end of the blog post. The JS files are viewable if you view source to get the URLs. That’s not as easy as a zip, but is the best I can do right now.

  • the_gurden

    Are there portions of the code I need to change that are unique to the animation? I’ve been trying to get this to work for awhile to no avail.

    • http://www.raymondcamdencom/ Raymond Camden

      Nope, not really. Unfortunately I no longer have a Creative Cloud subscription so I don’t have Edge Animate.

      • the_gurden

        righton, wasn’t sure you even checked this anymore. every google search even close to this leads right back to your article so you seem to be the only expert.

        i do get 3 console errors:

        two of them are:
        Cannot read property ‘stage’ of undefined

        the other says unexpected token in regard to the last line of the js. which is the last line of your code incidentally, has the project ID which i did change to my own (only thing).

        • http://www.raymondcamdencom/ Raymond Camden

          Best I can suggest is Adobe’s forums. I don’t use any Adobe software anymore for the most part. Frankly I’m surprised Edge Animate still exists. :)

          • the_gurden

            alright, much appreciated.

          • the_gurden

            shot in the dark here so sorry to bug you again.

            just realized i get this error: Cannot read property ‘top’ of undefined

            and when i run your demo that console error isn’t there. just not sure what the difference is and it’s driving me crazy.

          • http://www.raymondcamdencom/ Raymond Camden

            Is your demo online?

          • the_gurden


            just pushed up my local stuff. the empty white section is where the animation would appear.

          • http://www.raymondcamdencom/ Raymond Camden

            I was hoping to see something stand out, but nothing seems obvious to me. It is most likely the fact that EA has been updated and my code just no longer works. : As I said, I don’t have the software myself anymore so I’m not able to test it.

          • the_gurden

            yeah that’s kinda what i figured was going on. guess i didn’t realize this stuff is on it’s way out. all the adobe forums posts cite this so if this was the last bastion all is lost for this functionality with edge.

            thanks for taking the time though, really appreciate it!

          • http://www.raymondcamdencom/ Raymond Camden

            To be fair, me saying EA is on the way is *totally* my opinion and as I’m no longer at Adobe I have *zero* basis for that thought. I just tend to think Adobe’s concerns outside of Photoshop and the mobile apps around it is pretty much null. 😉