import React, { useEffect } from 'react';
import gsap from 'gsap';
const ComplexAnimationComponent = () => {
useEffect(() => {
const target = document.getElementById('animation-target');
if (target) {
const tl = gsap.timeline({
repeat: 2,
yoyo: true,
onRepeat: () => {
gsap.delayedCall(1, () => {
// 每次播放结束停顿1秒
});
}
});
tl.to(target, {
scale: 1.5,
rotation: 360,
x: 200,
duration: 2,
ease: 'power2.out'
})
.to(target, {
scale: 1,
rotation: 0,
x: 0,
duration: 2,
ease: 'power2.in'
});
return () => {
tl.kill();
};
}
}, []);
return <div id="animation-target" style={{ width: '100px', height: '100px', backgroundColor: 'blue' }}></div>;
};
export default ComplexAnimationComponent;