css - (React) 带有 css 模块的 CSSTransition

标签 css reactjs css-transitions

我正在尝试在我的元素中实现一个模态的 CSSTransition。问题是我正在使用 css 模块。

我的模态渲染方法

render() {
        return (
            <Aux>
                <Backdrop
                    show={this.props.show}
                    clicked={this.props.modalClosed}/>
                <CSSTransition
                    in={this.props.show}
                    timeout={1000}
                    mountOnEnter
                    unmountOnExit
                    classNames={?}
                >
                    <div
                        className={classes.Modal}
                    >
                        {this.props.children}
                    </div>
                </CSSTransition>
            </Aux>
        )
    }

我的 Modal.css
    .fade-enter {

    }

    .fade-enter-active {
        animation:openModal 0.4s ease-out forwards;
    }

    .fade-exit{

    }

    .fade-exit-active{
        animation: closeModal 0.4s ease-out forwards;
    }

为了使其工作,我将什么传递给 CSSTransition 组件中的 classNames 属性?

最佳答案

JSX:

  <CSSTransition in={focused} timeout={500} classNames={{
    enterActive: styles.MyClassEnterActive,
    enterDone: styles.MyClassEnterDone,
    exitActive: styles.MyClassExit,
    exitDone: styles.MyClassExitActive
  }}>
    <span className={styles.MyClass}>animated</span>
  </CSSTransition>

CSS 模块:
.MyClass {
  position: absolute;
  left: 5px;
}
.MyClassEnterActive {
  left: 15px;
  transition: left 500ms;
}
.MyClassEnterDone {
  left: 15px;
}
.MyClassExit {
  left: 15px;
}
.MyClassExitActive {
  left: 5px;
  transition: left 500ms;
}

谢谢 Lionel !

关于css - (React) 带有 css 模块的 CSSTransition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53912256/

相关文章:

javascript - 使用 Typescript 接口(interface) - 错误 : property does not exist

css - 如何让 'Reactjs Modal'出现在屏幕上从右到中飞

关键帧旋转动画后 CSS 旋转不动画

css - 图像不显示在 div 中

html - 不先点击就无法形成元素

javascript - 如何使用 Graphene 和 React Native 自定义 HTTP_USER_AGENT header ?

html - 简单的下拉菜单——悬停时的过渡

css - 如何(仅限 css)轻轻滚动到网页上的#name

html - 如何使用 CSS 控制标题 (H2) 的宽度?

javascript - 如何使用 twitter bootstrap 使按钮在悬停时亮起