Jump to content
Search Community

Need help with React footprints animation Scrolltrigger refresh not working

James23 test
Moderator Tag

Recommended Posts

I have issues with my code as the footprints will appear if I change some of my code .... but as soon as I refresh the page it disappears and no longer comes back. 

 

If anyone could help would be much appreciated and if you need more code from me let me know :)

 

 

<div className="a footprint"></div>
<div className="b footprint"></div>
<div className="c footprint"></div>
<div className="d footprint"></div>
<div className="e footprint"></div>
<div className="f footprint"></div>
<div className="g footprint"></div>
<div className="h footprint"></div>
<div className="i footprint"></div>
<div className="j footprint"></div>
<div className="k footprint"></div>
<div className="l footprint"></div>
<div className="m footprint"></div>
<div className="n footprint"></div>
<div className="o footprint"></div>
<div className="p footprint"></div>
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/ScrollTrigger.min.js"></script>

 

.footprint{
background-image:url("https://www.pcsoleil.fr/footprint.svg");
width:50px;
height:50px;
background-size: contain;
background-repeat: no-repeat;
transform: rotate(390deg);
position: absolute;
left: 600px;
opacity: 0;



 
}
 
.a{top:310px;}
.b{top:200px;left: 700px;transform: rotate(430deg);}
.c{top:150px;left: 850px;transform: rotate(430deg);}
.d{top:200px;left: 1000px;transform: rotate(141deg);}
.e{top:350px;left: 1100px;transform: rotate(135deg);}
.f{top:550px;left: 1300px;transform: rotate(150deg);}
.g{top:750px;left: 1350px;transform: rotate(190deg);}
.h{top:900px;left: 1300px;transform: rotate(176deg);}
.i{top:1100px;left: 1220px;transform: rotate(190deg);}
.j{top:1600px;left: 1100px;transform: rotate(200deg);}
.k{top:1740px;left: 1070px;transform: rotate(209deg);}
.l{top:1980px;left: 900px;transform: rotate(205deg);}
.m{top:2070px;left: 800px;transform: rotate(205deg);}
.n{top:1870px;left: 1000px;transform: rotate(203deg);}
.o{top:2150px;left: 690px;transform: rotate(206deg);}
.p{ top:2700px; left:320px; transform: rotate(180deg);}


 

 

 

import React from 'react';
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import "./Gallery.css";
import Gallery1 from "./Gallery1.png";
import Golfo from "./Golfo.png";
import School from "./School.mp4";
import Gambarie from "./Gambarie.png";
import { ImageViewer } from "react-image-viewer-dv";



 
gsap.registerPlugin(ScrollTrigger);













 
const Gallery = () => {
 
ScrollTrigger.batch(".footprint", {
 
start: "top 20%",
end: "bottom bottom",
onEnter: elements => gsap.to(elements, {opacity: 1, stagger: 0.1}),
onLeaveBack: elements => gsap.set(elements, {opacity: 0}),
scrub: true,
invalidateOnRefresh: false,
 
});
 
 
 
ScrollTrigger.refresh();
Link to comment
Share on other sites

The way you set up animations in React is different than you would in vanilla js, as the dom is virtual, and elements are dynamically added: This article should get you started:

 


Also:

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

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

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

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

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...