Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: Best way to do the function after page load

I use google converted swiffy script like this

var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),swiffyobject);
stage.start();

My point is I want to do the action after the animation end. but I don't know how to track the frame on swiffy object.

this is my work before asking

  • I put start method after page is loaded on

    $(document).ready

    $(window).load

    window.onload =

and track the time (random test to reach the last frame) with

setTimeout(callAtEnd(),10000);

result: not work; like it count the time when page is rendering, not after complete rendered

  • let it start method and put setTimeout on load (should count after complete rander

result: not work either

Please help or give other solution to do.

Many thanks.

like image 746
user1128331 Avatar asked Jan 27 '26 13:01

user1128331


2 Answers

$(document).ready() will fire when the DOM is ready, but before the browser has finished loading all external resources.

window.onload will fire when the browser has finished loading all external resources. However, there may still be other operations being performed asynchronously.

Neither of these will give you a 100% accurate timing with relation to the swiffy timeline.

What you would need to do is add some ActionScript that will fire when the animation is complete. Since Swiffy only supports a subset of Actionscript, the simplest way is to have your Flash call a Javascript function by using the getURL() function, such as:

getURL("javascript:animationIsComplete();");

This way, Swiffy can call your completion handler directly without any need for timing page loads.

See Is there any way to detect when a Swiffy animation has completed?

like image 144
nullability Avatar answered Jan 29 '26 02:01

nullability


You can call it in two ways:

document.onload=function() {}

window.onload = function() {}

The best to use is document.onload because it separates content structure from code, but it all depends on the amout of javascript you have.

If you want to use jQuery its:

$(document).ready() {}
like image 29
António Regadas Avatar answered Jan 29 '26 02:01

António Regadas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!