I have created an animation in Adobe Animate, which I want to use as a preloader. The output of this animation is a script & style (which I put in the head) and some elements (divs) which are in the body right after the body tag.
What triggers the script is the onload="init()"; attribute placed inside the body tag. The problem I have with this is that the animation starts just after the whole body (including the content - for which I created the preloader in the first place) is loaded. So I think the script in the head runs just after the body loads.
So my question is how can I trigger the script after the first div with the animation elements is loaded so the animation could run while the rest of the content is loaded? - so basically to act like a preloader.
This is the structure.
<html>
<head>
<link rel='stylesheet' href='...preloader-animation.css' type='text/css' media='all' />
<script type='text/javascript' src='...preloader-animation.js'></script>
</head>
<body onload="init()";>
<div id="animation_container">
...animation elements...
</div>
...rest of the content (images, video, etc. not markup)
</body>
</html>
I've also tried to place the trigger below the animation div like this
<script type="text/javascript">
window.onload = function() {
init();
};
</script>
or
<script type="text/javascript">
document.onload = function() {
init();
};
</script>
but it's still waiting for the whole page to load before playing.
Thanks