Sai*_*cko 3 javascript css keyframe css-animations reactjs
我正在编写一个带有可变数量组件的滚动自动收报机,因此我需要translate3d它根据组件数量更改它的移动距离。我能想到的唯一方法是以某种方式从JSX文件中传递一个数字,但我找不到办法做到这一点。有没有办法传递CSSa 变量,或者其他一些方法来做我想做的事?
有几个« CSS in JS »库允许您添加keyframes到您的组件动画。当您在 JavaScript 中编写样式时,您可以直接使用组件 props/states 或其他一些常量来创建组件样式。
以下 3 个库具有关键帧支持(我个人一直在使用第一个):
import styled, { keyframes } from 'styled-components';
const rotate360 = keyframes`
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
`;
const Rotate = styled.div`
display: inline-block;
animation: ${rotate360} 2s linear infinite;
`;
Run Code Online (Sandbox Code Playgroud)
import { css } from 'glamor'
let bounce = css.keyframes('bounce', {
'0%': { transform: 'scale(0.1)', opacity: 0 },
'60%': { transform: 'scale(1.2)', opacity: 1 },
'100%': { transform: 'scale(1)' }
})
<div {...css({
animation: `${bounce} 2s`,
width: 50, height: 50,
backgroundColor: 'red'
})}>
bounce!
</div>
Run Code Online (Sandbox Code Playgroud)
const translateKeyframes = {
'0%': { transform: 'translateX(0)' },
'50%': { transform: 'translateX(100px)' },
'100%': { transform: 'translateX(0)' },
};
const opacityKeyframes = {
'from': { opacity: 0 },
'to': { opacity: 1 }
};
const styles = StyleSheet.create({
zippyHeader: {
animationName: [translateKeyframes, opacityKeyframes],
animationDuration: '3s, 1200ms',
animationIterationCount: 'infinite',
},
});
<div className={css(styles.zippyHeader)}>...</div>
Run Code Online (Sandbox Code Playgroud)
希望有帮助!:)
| 归档时间: |
|
| 查看次数: |
4428 次 |
| 最近记录: |