【发布时间】:2017-01-04 04:56:16
【问题描述】:
我正在使用 React TransitionGroup 和 Velocity 来动画路线之间的过渡。
我正在尝试制作一个简单的动画,其中目标路由组件从左侧滑入,源路由从右侧滑出。
我现在正在运行该动画,但它们没有垂直对齐。也就是说,新组件被添加到旧组件之上的 dom 中,因此我们得到了下面屏幕截图中的内容。这是我们从编辑导航到预览的时候。表单标题是编辑的一部分,并在预览进入时被推到底部。
这是动画运行时 DOM 的样子。
我确定我只需要一些 css 来实现这一点,但不知道如何去做。
预览代码示例:
import React from 'react';
import ReactDom from 'react-dom';
import Velocity from 'velocity-animate';
import 'velocity-animate/velocity.ui';
class Preview extends React.Component{
componentWillEnter(callback){
const el = ReactDom.findDOMNode(this);
if (!el) {
console.error('not el!', el);
}
Velocity(el, 'transition.slideLeftBigIn', {duration: 1000, complete: callback});
}
componentWillLeave (callback) {
const el = ReactDom.findDOMNode(this);
console.log('otw out')
Velocity(el, 'transition.slideRightBigOut', {duration: 1000, complete: callback});
}
render(){
return (
<div>
<h2>Preview</h2>
<img src=""/>
</div>
);
}
}
App.jsx 中的转换组定义
<TransitionGroup>
{React.cloneElement(this.props.children, {
key: Math.random()
})}
</TransitionGroup>
【问题讨论】:
标签: javascript css reactjs velocity.js