【发布时间】:2019-07-31 12:52:59
【问题描述】:
我有一个渲染网格元素的功能组件。我想通过用 HOC 包装它来为该组件提供 Anime.js 动画。 问题是“我如何以正确的方式实现它以及如何从 WrappedComponent 中选择所需的目标元素?”。
import React, { PureComponent } from 'react';
import anime from 'animejs/lib/anime.es.js';
function withAnimation(WrappedComponent) {
return class extends PureComponent {
handleAnimation = () => {
anime({
targets: 'targets are in WrappedComponent',
translateY: [-30, 0],
easing: 'easeInOutQuad',
duration: 2000,
})
}
componentWillMount(){
this.handleAnimation()
}
render() {
return <WrappedComponent {...this.props}/>;
}
};
}
export default withAnimation;
【问题讨论】:
标签: javascript html css reactjs anime.js