【发布时间】:2018-07-20 02:44:56
【问题描述】:
我对 GSAP 有疑问并做出反应,正如我从一些教程中读到的那样,它们都使用 react-transition-group 并且其中许多使用 ref 作为 GSAP 的替代选择器,但是,如果我在我的情况下使用 ref ,整个页面都会被动画化,我只想要一个元素来动画化,所以我使用了 id 选择器,它就像这样工作得很好
import React from 'react';
import { TweenMax } from 'gsap';
import uuid from 'uuid';
import '../styles/homePage.css';
class HomePage extends React.Component{
startAnimation=(pic)=>{
TweenMax.from(`#${pic.id}`, 1, {
opacity: 0,
x: -100,
y: -100
});
}
render(){
const PicsNum = 15;
let pics = [];
let pic = {};
for (let i = 5; i <= PicsNum; i++) {
const picPath = `/pictures/testingPics/${i}.jpg`
pic={id:`a${uuid()}`, picPath}
pics.push(pic)
}
const renderPics = pics.map((p, i) => (
<div
key={i}
className='img-container'
>
<img src={p.picPath} className='pic' id={p.id}/>
<button onClick={()=>{this.startAnimation(p)}}>click</button>
</div>
))
return (
<div className='pics'>
{renderPics}
</div>
)
}
}
export default HomePage;
有人能告诉我为什么要使用 react-transition-group 吗?如果我想像现在这样在没有它的情况下使用动画会出现什么问题?非常感谢
【问题讨论】:
标签: reactjs animation css-transitions ref gsap