gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:58:56 24 4
gpt4 key购买 nike

我目前正在研究 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com