0

Im using the library animate https://daneden.github.io/animate.css/

For adding an animation to whatever you have to add the class animate + nameOfAnimation for example

I want to add a second animation when a button is clicked so I figured something like

<button class="heroe-button animated fadeInLeft" (click)="addClass()"> </button>

addClass():void{
$('.heroe-button').removeClass('fadeInLeft');
$('.heroe-button').addClass('fadeOutRight');
}

But that doesn't do anything.. I have also tryed to add and remove opacity to reset the animation and neither. Few little other tricks but none succesfull.

(Basically what i want to do is that a button fadesin animated and when pressing the button it fades out also animated..

3
  • 1
    Just adding the class is not enough... if you are interested in how it works and how to solve the problem, have a read here: css-tricks.com/restart-css-animation Commented Oct 29, 2017 at 21:03
  • yes!!!! perfect!!!!!!!!!!! (I was wrong but not that much after all!!!! Commented Oct 29, 2017 at 21:32
  • @Alex did my answer help? Commented Nov 1, 2017 at 14:29

2 Answers 2

1

This example is from the link @Jan Hamara shared in the comment.

<button class="heroe-button animated fadeInLeft" (click)="addClass()"> </button>

$(".heroe-button").click(function() {
        var el = $(this);

        el.before( el.clone(true) ).remove();
    });

This will create a cloned element and then removes the original element. This way will restart the animation.

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

3 Comments

yes!!!! perfect!!!!!!!!!!! (I was wrong but not that much after all!!!!
I'm glad it helped! :)
@Alex I just noticed you unmarked my answer. Did it not work for you?
0

I think adding jquery to angular would be a bad idea, why not make use of ngClass

[ngClass]="{'style1': isClass1Visible, 'style2': isClass2Visible}"

So in your code it would be like:

<button class="heroe-button animated" [ngClass]={'fadeInLeft': isVisible, 'fadeOutLeft': !isVisible} (click)="changeVisibility()"> </button>

changeVisibility() {
     //Change isVisible variable
}

More documentation on ngClass over here: https://angular.io/api/common/NgClass

Comments

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.