I have simple animations on a homepage component that works amazingly when I first visit the page or if I just refresh with F5:
@ViewChild('section1', {static: true}) section1: ElementRef<HTMLDivElement>;
@ViewChild('section2', {static: true}) section2: ElementRef<HTMLDivElement>;
ngOnInit(): void {
this.initScrollAnimation();
}
ngOnDestroy() {
ScrollTrigger.refresh();
}
initScrollAnimation(): void {
gsap.utils.toArray<HTMLElement>(".defil
you need to wrap your function in a setTimeout func.
"Invoking setTimeout with a callback, and zero as the second argument will schedule the callback to be run asynchronously, after the shortest possible delay - which will be around 10ms and the JavaScript thread of execution is not busy."
import { Component, OnInit } from '@angular/core';
import {gsap } from 'gsap';
import ScrollTrigger from 'gsap/ScrollTrigger';
gsap.registerPlugin( ScrollTrigger );
@Co