Jump to content
Search Community

Ethan Wood

Members
  • Posts

    1
  • Joined

  • Last visited

Ethan Wood's Achievements

  1. I try to briefly describe my problem: I wrote a React application to generate a series of animations on a web page. Each element can be added with gsap animation effects. The animation can be rendered by passing the animation configuration parameters corresponding to this element to gsap. For example, to Implementing an animation that rotates an element will go through the following process: const config = { duration: 3, rotate: 360, delay: 1, } const element = "#text-element-1"; const timeline = gsap.to(element, config); Now, I will store the config corresponding to each element in redux, and then implement the function of modifying the config of the element through a form. This animation parameter is passed to gsap. Now, when I modify the animation parameters of an element and submit it to redux, the program will read the new config and recreate a gsap timeline instance. I use this timeline to control the animation by calling play () and other methods. Problem Description: ① When I use a default config to pass to gasp, the animation can be executed smoothly, the following is the correct animation execution (check the style attribute change of the dom element) ② But whenever I modify the config of the element, a timeline instance will be regenerated. At this time, the timeline instance will be called again, and the animation will not respond. However, I checked the dom and found that the style attribute was indeed updated by gasp , but not the correct one. You can clearly see the difference. After regenerating the timeline instance, gasp does change the style attribute of the element, but it should be done gradually, not all at once. Because of the complexity and size of the entire application, I can't provide an example through codepen, sorry. But I have provided partial examples and code screenshots with similar logic, I hope you can help me see. This code reads the element's config and then generates a masterTimeline instance: const keyframes: keyframesData = useSelector((state: any) => state.anime.keyframes); const hasKfrChange = useSelector((state: any) => state.anime.hasKfrChange); const [timeline, setTimeline] = useState(gsap.timeline({ paused: true })); useEffect(() => { const fragment = gsap.timeline({ paused: true }); if (keyframes) { Object.values(keyframes).forEach((value: any) => { fragment.add(animeExe(value), "<"); setTimeline(fragment); }); } else { throw new Error("data type of keyframesdata is only can be object"); } }, [hasKfrChange]); Parameter explanation: keyframes is an object that stores the config of each element. I will traverse to get all the animation parameters, and then pass them to animeExe. The role of animeExe is to accept the current incoming config, then generate a timeline instance, and return this value. Like this: timeline.to('#my-element', config); return timeline; A series of elements are contained in a keyframes object, and then, gsap animations of all elements will be added to the timeline instance, and finally will be added to the main timeline masterTimeline to realize gsap animation generation of a series of elements. So, my question is, why the different timeline instances re-create according to different configs are only valid when they are called for the first time, but are invalid after modifying the config?
×
×
  • Create New...