适用于任何框架的 Javascript 动画库 \ Animation of all Javascript frame
Animation of all Javascript frame
Use bezier-easing: https://github.com/gre/bezier-easing
import Anim from './Anim.js'
render() {
return (
<div style={{
transform: `translateX(${this.state.x}px)`,
width: 200,
height: 200,
backgroundColor: '#f00',
color: '#fff',
}}
onClick={this.handleClick}
>
Touch Me!
</div>
)
handleClick = ()=>{}
}
handleClick = () => {
let move = Anim.init(0.5, (p) => {
this.setState({
x: Anim.motion(0, 100, p)
})
})
move.play()
}
Anim.init(time, function)
let an = Anim.init(0.3, (value)=>{console.log(value)})
an.play(()=>{console.log('animation is end')})
value is 0~1 in 0.3 second
Anim.motion(startValue, endValue, value)
let an = Anim.init(0.3, (value)=>{
let per = Anim.motion(50, 150, value)
console.log(per)
})
an.play()
let an = Anim.init(0.3, (value)=>{
let per = Anim.motion(50, 150, value)
console.log(per)
})
an.easing = Anim.ease.spring
//or
an.easing = [0.25, 0.5, 0.7, 1]
an.play()
an.delay = 10
an.yoyo = true
an.replay = 10
an.play()
an.play(()=>{console.log('animation is end')})
an.stop()