Jump to content
Search Community

gsap not working inside angular project in FireFox

AnnaDVD test
Moderator Tag

Recommended Posts

Hello!. Please help me to understand what I am doing wrong. The code works in the demo in codepen, but when I inject it into my angular project it doesn't work in FireFox:
ts:

import { Component, OnInit } from '@angular/core';
import gsap from 'gsap';
import ScrollTrigger from 'gsap/ScrollTrigger';

@Component({
    selector: 'app-home2',
    templateUrl: './home2.component.html',
    styleUrls: ['./home2.component.scss']
})
export class Home2Component implements OnInit {

    constructor() { }

    ngOnInit(): void {
        // Register ScrollTrigger plugin
        gsap.registerPlugin(ScrollTrigger);

        // Define your GSAP animation timeline
        const tl = gsap.timeline();

        // Use ScrollTrigger with GSAP animations
        tl.from(".line span, .line p", {
            duration: 1.8,
            y: 100,
            ease: "power4.out",
            delay: 1,
            skewY: 7,
            stagger: {
                amount: 0.3
            },
            scrollTrigger: {
                trigger: ".line", // Adjusted trigger element to include both span and p
                start: "top 80%", // Adjust as needed
                end: "bottom 20%", // Adjust as needed
                toggleActions: "play none none reverse",
                markers: true // Set to true for debug markers
            }
        });
    }
}

scss:
 

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap');

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

html, body{
  background-color: black;
  color: white;
  font-family: 'Roboto', sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.container{
  width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .line{
    width: 70%;
    height: 70px;
    position: relative;
    overflow: hidden;
    span{
      position: absolute;
      font-size: 3rem;
      line-height: 4.2rem;
    }
  }
}



HTML:
<div class="container">
  <div class="line">
    <span>Hello!</span>
  </div>
  <div class="line">
    <span>This is a</span>
  </div>
  <div class="line">
    <span>text reveal animation.</span>
  </div>
</div>


 

Link to comment
Share on other sites

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Hi @AnnaDVD and welcome to the GSAP Forums!

 

Unfortunately we don't have a lot of experience with Angular around here, so we don't have a starter template for GSAP on an Angular app. Also 

vague details like 'it's broken' or 'it doesn't work' are very difficult for people to help with. Here are some tips that will increase your chances of getting a relevant answer:

  • A clear description of the expected result - "I am expecting the purple div to spin 360degrees"
  • A clear description of the issue -  "the purple div only spins 90deg"
  • A list of steps for someone else to recreate the issue - "Open the demo on mobile in IOS safari and scroll down to the grey container" 

You can create a demo on Stackblitz by clicking new project and then selecting the Frontend tab:

95k2HLs.png

Finally from your code snippet I can see that you're adding a ScrollTrigger to a child instance inside of a Timeline. We strongly recommend against doing that:

https://gsap.com/resources/st-mistakes#nesting-scrolltriggers-inside-multiple-timeline-tweens

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...