reactjs - React CSSTransitionGroup 不起作用(不添加类)

标签 reactjs animation

我目前正在研究 React 中的通知组件。除了转换之外,它正在工作。不知何故,它甚至没有添加类。我查找了一些 React 动画示例并做了一些研究,但我找不到任何有用的东西。特别是针对 React15 的文章。我不明白,这应该可以完美工作,但它只是显示和隐藏文本,没有任何转换。

import React, { Component } from 'react';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import '../stylesheets/notification.less';

export default class Notifications extends Component {
    render() {
        return (
           <CSSTransitionGroup transitionName="notifications" transitionEnterTimeout={300} transitionLeaveTimeout={300}>
                    <div className={this.props.type === 'error' ? 'notification-inner warning' : 'notification-inner success'}>
                      {this.props.type} {this.props.message}
                    </div>
            </CSSTransitionGroup>
        );
    }
}

还有 CSS 文件...

.notifications {
    background:#000;
}
.notifications-enter {
    opacity: 0;
    transform:   translate(-250px,0);
    transform: translate3d(-250px,0,0);
}
.notifications-enter.notifications-enter-active {
    opacity: 1;
    transition: opacity 1s ease;
    transform:   translate(0,0);
    transform: translate3d(0,0,0);
    transition-property: transform, opacity;
    transition-duration: 300ms;
    transition-timing-function: cubic-bezier(0.175, 0.665, 0.320, 1), linear;
}
.notifications-leave {
    opacity: 1;
    transform:   translate(0,0,0);
    transform: translate3d(0,0,0);
  transition-property: transform, opacity;
    transition-duration: 300ms;
    transition-timing-function: cubic-bezier(0.175, 0.665, 0.320, 1), linear;
}
.notifications-leave.notifications-leave-active {
    opacity: 0;
    transform:   translate(250px,0);
    transform: translate3d(250px,0,0);
}

最佳答案

确保您已设置关键属性。

来自文档:https://facebook.github.io/react/docs/animation.html

Note: You must provide the key attribute for all children of ReactCSSTransitionGroup, even when only rendering a single item. This is how React will determine which children have entered, left, or stayed.

关于reactjs - React CSSTransitionGroup 不起作用(不添加类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43496371/

相关文章:

javascript - React Native 中的条件导入

javascript - 非矩形、Canvas 或 SVG 形状内的背景动画?

android - 如何获得Lottie动画中可用的总帧数?

jquery - 使用 jQuery 检测 animate.css 的动画状态和动画结束状态

jquery - Css3 动画播放两次而不是一次

html - 使用 CSS 为句子中的单个单词制作动画

security - react +路由+安全

javascript - 如何在react.js中使用json

javascript - 导入变量,但在使用 ReactJS Redux 时出现导入错误

javascript - 如何在没有 nodeJs 的情况下在 javascript 文件中加载 react