1

I'm trying to animate the logo on my app home screen so after 2 seconds the logo fades in and begins a looped animation after the fade is complete to bob up and down.

I've thought of adding a timeout in the controller like this:

$timeout(function(){
    $scope.animationClass = 'animateOn';
});

And then trigger the animation when the class is added to the dom.

However I think it may be best to put this animation delay code in a directive as it will separate the code and make it reusable.

I just wondered if there's an easier way of doing this as I'm new to animating with Angular JS.

EDIT:

I've made a directive to add a class after a delay. This works great, but is there an easier alternative? See below:

.directive('animationDelay', function($animate,$timeout) {
    return function(scope, elem, attr) {
        $timeout(function() {
            $animate.addClass(elem, 'my-animate');
        }, attr.animationDelay);
    };
});

Called by using:

<img animation-delay="3000" id="mainLogo" src="img/logo.svg" class="homeLogo" />

Thanks

1 Answer 1

1

CSS3 syntax provides a property to delay an animation, animation-delay

You can set the delay to the amount you want, declare the style in a class, and assign the class to the element. You can use the same 'my-animate' class and include the animation delay there More info

If you want to display the effect after an element appears on screen with ng-show, angular has a library for animations that will come handy, ngAnimate

Sign up to request clarification or add additional context in comments.

1 Comment

I did try using the animation-delay CSS property, but this did not work for custom transitions. The element was showing on screen before the animation happened. You can't manually add a delay to the ng-show either to hook into ngAnimate so that's why I thought of using the directive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.