I'm new to Angular, so if I'm doing any of these steps all wrong please set me straight.
I am trying to get the clamps on the left and right side of my website to animate in on initial page load. Here it is in production: https://www.robotsidekick.com
As you can see it currently works (yay). However I'm not happy with the hack that I'm using. Here is the pertinent code:
In my controller I am listening for $routeChangeStart
and if it's the first time through I call:
setTimeout(function() {
angular.element(document.querySelector('.robotarmleft')).addClass('animate-in');
angular.element(document.querySelector('.robotarmright')).addClass('animate-in');
}, 0);
That grabs the two clamps, adds the class animate-in
which has the following CSS properties:
.robotarm {
margin-left: -2048px;
margin-right: -2048px;
}
.animate-in {
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-o-transition: all 2s ease;
transition: all 2s ease;
margin-left: -1300px;
margin-right: -1300px;
}
So the arms are (hopefully) off screen, and they animate in.
If however I add the class to the robot arms not in that setTimeout
the animation isn't triggered at all.
Why does that addClass
have to be in a setTimeout
to work? Should I kick off the animation in some other onPageLoadTheFirstTime
type even for Angular? Mostly looking for the right way to do this sort of thing not so much a well this other hack works great too.
Thanks for the help!