我正在构建一个显示none或block的组件,这取决于它是isActive支柱。
我已经设法使它成为slideInDown,使用react-animations和styled-components这样的方式。
import styled, { keyframes } from 'styled-components';
import { ifProp } from 'styled-tools';
import { slideInDown } from 'react-animations';
const slideInAnimation = keyframes`${slideInDown}`;
const MyComponent = styled.div`
animation: 0.4s ${slideInAnimation};
display: ${ifProp('isActive', 'block', 'none')};
`;我要把它变成slideOutUp。但是,我不知道如何同时实现slideInDown和slideOutUp动画。
我怎么才能做到呢?
注释:工作的。但我不知道怎么才能让它既滑又滑。我试过像下面这样的东西,但那不管用。
import styled, { keyframes } from 'styled-components';
import { ifProp } from 'styled-tools';
import { slideInDown, slideOutUp } from 'react-animations';
const slideInAnimation = keyframes`${slideInDown}`;
const slideOutAnimation = keyframes`${slideOutUp}`;
const MyComponent = styled.div`
animation: 0.4s ${slideInAnimation}, 0.4s ${slideOutAnimation};
display: ${ifProp('isActive', 'block', 'none')};
`;发布于 2018-04-17 11:48:19
我翻阅了react-animations库,我发现的是slideOutUp集visibility: 'hidden.'
const slideOutUp: Animation = {
from: {
transform: translate3d(0, 0, 0)
},
to: {
visibility: 'hidden',
transform: translate3d(0, '-100%', 0)
}
};您可以使用animation-fill-mode: forwards,这有助于在动画结束后保留样式。
您可以这样做(它起作用):
const MyComponent = styled.div`
animation: ${ifProp(
"isActive",
`0.4s ${slideInAnimation}`,
`0.4s ${slideOutAnimation} forwards`
)};
`;下面是工作示例,为了测试目的,我正在设置onClick事件{isActive: false}
发布于 2018-04-17 10:24:35
Display没有动画。您需要使用不透明度来切换(1到0,反之亦然)和动画。
const myComponent = styled.div`
animation: 0.4s ${slideInAnimation};
opacity: ${ifProp('isActive', 1, 0)};
`;考虑到您的代码正在像您告诉我的那样工作,您可以在动画中使用无穷属性:
animation: 0.4s ${slideInAnimation} infinite;我想它解决了你的问题。
https://stackoverflow.com/questions/49875586
复制相似问题