Answer the question
In order to leave comments, you need to log in
Why doesn't animation work in react?
Hello.
I'm making a chat with react/redux . On the page, I get an array from redux with all the dialogs and a loop for drawing an open button for each of them.
You need to add an animation to open each dialog.
To do this, I add the field animate = true to the opened dialog reducer ;
And when rendering the page, I check if this field is true, then I add the dialog_animate
class to the element.
Here is the component code:
class PageDialogs extends Component {
sortDialogs(dialogs){
return dialogs.sort(function(a, b){
if (a.openedAt < b.openedAt) {
return -1;
}
else if (a.openedAt > b.openedAt) {
return 1;
}
else {
return 0;
}
});
}
showDialogs(){
return this.props.dialogs.map(function(dialog, key){
if (dialog.active) {
return (
<div key={key} className={dialog.animate ? 'dialog_animate' : ''} >
<Dialog dialog={dialog} />
</div>
);
}
})
}
render() {
if (typeof this.props.dialogs !== 'undefined') {
return (
<div>
<div className='page-dialogs'>
{this.showDialogs()}
</div>
</div>
);
}
else {
return (
<div>
<Preloader />
</div>
)
}
}
}
.dialog_animate {
animation: dialog_animate 5s ease-in-out forwards;
-webkit-animation: dialog_animate 5s ease-in-out forwards;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question