Delaying an Edge Animate asset until visible - Part 5

This post is more than 2 years old.

So, in my last post on this topic, I mentioned that I was surprised at how many times this "simple" topic kept coming up on my blog. In a way, this has turned into the series that just won't die - no matter how many times I think I've covered every little detail.

But much like how some movie franchises seem to find a way to just keep chugging along, so is this particular series of tips on Edge Animate. Today's post is more of an addendum though so be sure you've read the earlier articles. (I've linked them all at the bottom.)

This weekend I worked with a client who asked me to simply add my "Don't start until visible" code to the page. I thought it was going to be easy but I ran into two issues. The first one was that he was using the minified code in production and needed a way to disable autoplay. He still had the EA project files, but unfortunately they appeared to be a different version. Why do I say that? I opened his project, disabled autoplay, saved, and then did a diff on the generated files. I saw multiple changes, not just one. Maybe I did something wrong, or maybe I was worrying about something I didn't need to, but I began looking at the minified JS file to see if I could correct it there.

I was able to find the code I needed to change, but I urge people to consider carefully before they follow this advice. I'm not confident that how the Edge code is minified in the future won't change. This worked for me this weekend, but I'd suggest against modifying the code this way unless you really have to. With the warning in mind, if you find the foo_edge.js file (where foo is the name of your project), look for "Default Time" in the code. You should see something like this:

tl:{"Default Timeline":{fS:a,tS:"",d:3000,a:y,tt:[]}}

In the block above, the a key represents autoplay. Setting it to n will disable it.

tl:{"Default Timeline":{fS:a,tS:"",d:3000,a:n,tt:[]}}

Ok, so that ended up being the easy issue. What I found next was that my code always thought it was visible, even when it wasn't. Turns out, the client was using an object tag to embed the EA asset. I've seen other people do this as well. It is a way to embed an EA asset into an already designed page. Here's the issue though. My code looks at the value of window to see how far scrolled the user is and how it compares to the position of the asset.

In a case where the asset is in an object tag, the window object represents the object tag, not the "real" window. In that case, the asset is positioned on top, which means my code thinks it is immediately visible. The modification to fix this isn't too hard though. Here is the entire block that goes inside the creationComplete handler. (And again, I'm assuming you've read the earlier posts. If you have not, please do so first.)

Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {

	// insert code to be run when the symbol is created here
	var wasHidden = true;

	function isScrolledIntoView(elem) {
		var docViewTop = $(window.parent).scrollTop();
		var docViewBottom = docViewTop + $(window.parent).height();

		var elemTop = $(elem).offset().top;
		var elemBottom = elemTop + $(elem).height();

		return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
		  && (elemBottom <= docViewBottom) &&  (elemTop >= docViewTop) );

	var element = sym.element;
	element = $("#EdgeID", window.parent.document);

	if(isScrolledIntoView(element)) {
		console.log('on load vis');

	function doStart() {
		if(isScrolledIntoView(element)) {
			if(wasHidden) {
				console.log('Start me up ID5');;
			wasHidden = false;
		} else {
			wasHidden = true;


	$(window.parent).on("scroll", doStart);


The first change is to redefine element, the asset. Instead of referring to the asset itself, I'm using the ID value of the object tag in the parent document. This is important as I'm changing the entire context of how I check for visibility. Switching from "asset in window" to "thing holding my asset to the top window."

The next change is to the isScrolledIntoView method. I changed the two references of window to window.parent. And that's it. Now - to be clear - this assumes a "two level" DOM. It is possible that someone could do an object tag pointing to an HTML page that used yet another object tag. But that would be overkill and I'm sure no one will. (And because I said that - someone will.)

Anyway, I believe I ran into people who were using object tags before and I'm also thinking that my code failed for them. Hopefully this version will work better.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Peter posted on 6/23/2014 at 1:55 PM

Hello Raymond, first of all thanks for all the knowledge.

I'm trying to use your code for a couple of days now, I've been reading all of it's parts. I just can't seem to figure it out. I don't know if I have to change something on the code to adapt it to mine.

The thing is, I have an animation of a little guy coming out of an underground hole and that animation is on the footer of the screen. I want this animation to play when the user goes to that section of the screen. I'm putting your code on creationComplete, and I must admit I'm quite an amateur with coding, so I bet I'm doing something wrong, but the animation just won't run, it's frizzed and if I apply the Auto Play it just plays normally without waiting for me to scroll.

Thanks in advanced!

Comment 2 by Raymond Camden posted on 6/23/2014 at 6:15 PM

Is it online where I can see?

Comment 3 by Peter posted on 6/23/2014 at 7:25 PM

Yes -it's in process- but here it is.


The hole on the ground is the animation. The guy comes out of that hole.

Comment 4 by Raymond Camden posted on 6/23/2014 at 8:11 PM

I see you are using an iframe, which is slightly different than what I dealt with above. In theory it should have worked the same. I'm going to have to try to debug this myself on a simple iframe demo locally. It's that or you give me FTP access to your box to try to diagnose it directly there.

Comment 5 by Raymond Camden posted on 6/23/2014 at 8:12 PM

Actually it may be simpler. See this line:


This expected to match the OBJECT id in the parent document. You are using an iframe with id of U1132_animation. Try using that value. (Don't forget to put the # in front.)

Comment 6 by Peter posted on 6/23/2014 at 8:49 PM

Hello Raymond, many thanks on your replies.

I would totally would share with you the FTP information but I'm using Adobe Muse's and I don't even know how it is.

I've tried with that ID but doesn't work and I think it is cos every time I publish it, the ID changes...I've seen this by inspecting the element on Google Chrome and every time I made changes the ID was different.

Thanks again.

Comment 7 by Raymond Camden posted on 6/23/2014 at 8:52 PM

Hmm - if you can't stop that from happening, I'm not sure what to suggest. This may, stress, MAY work:


Comment 8 by Peter posted on 6/23/2014 at 9:48 PM

Thanks Raymond, I'm burning my brain right now...I think I smell barbecue.

I will definitely post the solution here if I ever find it...but I'm sure it has to do with that iframe id that's changing and I can't find a way to say to the code "this is the animation"

Comment 9 by Raymond Camden posted on 6/23/2014 at 9:52 PM

I just noticed you have 2 iframes on the page, so my code would have matched the first one. You would need to handle that.

Comment 10 by Peter posted on 6/23/2014 at 10:04 PM

Those iframes are 2 different Adobe Edge animations (the plane and the hole). I'm working the website inside Muse cos like I said earlier I'm quite a noob on coding. I bet there's a way to name them like I want to and put that name on your code, I just can't find it.

Comment 11 by Jason posted on 7/9/2014 at 7:01 AM

Hi Raymond,

I've been trying to adapt this for a horizontal scroll and can't for the life of me get it to work ...
Is it not as simple as using

function isScrolledIntoView(elem) {
var docViewLeft = $(window).scrollLeft();
var docViewRight = docViewLeft + $(window).innerWidth();

var elemLeft = $(elem).offset().left;
var elemRight = elemLeft + $(elem).width();

return ((elemRight >= docViewLeft) && (elemLeft <= docViewRight)
&& (elemRight <= docViewRight) && (elemLeft >= docViewLeft) );


Comment 12 by Jason posted on 7/9/2014 at 7:07 AM

here is my current .html ...

and associated project files ...

thanks for any assistance :)