import React, { useState } from "react";
import { Button } from 'antd'
import cs from 'classnames'
import './styles.less'
// animation 自动执行
// transform transition 用户主动触发
// 动画事件监听
// 开始事件 ,结束事件,重复运动事件
export default function Animation(props) {
const [x, setX] = useState(false)
const onClick = () => {
setX(true)
}
return (
<div styleName="animation">
<div styleName={cs('animation-box', { xxx: x })}></div>
<Button onClick={onClick}>滚动</Button>
<div styleName="animation-box2"></div>
</div>
)
}
.animation {
.animation-box,
.animation-box2 {
width: 100px;
height: 100px;
border-radius: 100px;
background: #99f;
transition: transform 1s ease;
}
.xxx {
transform: translate3d(200px, 0, 0);
}
@keyframes x1 {
0% {
transform: translate3d(0, 0, 0);
}
50% {
transform: translate3d(100px, 0, 0);
background: pink;
width: 200px;
}
100% {
transform: translate3d(200px, 0, 0);
}
}
.animation-box2 {
animation: x1 1s ease-in-out 0s 5 alternate;
}
}