Jump to content
Search Community

Markers Overlap and Targeted Element Markers Not Visible in React with ScrollTrigger Timeline

VMS test
Moderator Tag

Recommended Posts


Hello everyone,

I'm currently working on a React application and have been trying to create an animation where a specific section within one of my components gets pinned, and upon completion of its animation, it should scroll down to the next component. However, I've run into an issue when applying ScrollTrigger and creating a timeline for an element within my component.

The problem I'm experiencing is that the start and end markers of the viewport coincide, and the markers for my targeted element are nowhere to be seen. Additionally, the position of the screen marker has shifted, and a strange line appears, covering the entire width of my screen.

I'm including the relevant code snippet from my component for reference:

 

 

import React, { Fragment, useRef, useLayoutEffect } from "react";
import "./style/main.css";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
function Main() {
  const app = useRef();
  useLayoutEffect(() => {
    let ctx = gsap.context(() => {
      var tl1 = gsap.timeline({
        scrollTrigger: {
          trigger: ".box2",
          start: "0% 50%",
          end: "50% 50%",
          scrub: "true",
          markers: "true",
        },
      });
    }, app);
 
    return () => ctx.revert();
  }, []);
  return (
    <>
      <div ref={app} className="App">
        <div className="box1">
          <div className="box">selector</div>
        </div>
        <div className="box2">
          <div className="boxx">selector</div>
        </div>
      </div>
    </>
  );
}
export default Main;

Css for this component is 

body {
  background-color: var(--dark);
  color: var(--light);
  font-family: "Signika Negative", sans-serif;
  margin: 0;
  padding: 0;
  height: 100vh;
}
 
.box {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-color: var(--green);
  font-weight: 600;
  color: var(--light);
  transition: cubic-bezier(0.165, 0.84, 0.44, 1);
}
 
.App {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: space-around;
  min-height: 100vh;
}
 
.box1{
  background-color: #ffffff;
  height: 100vh;
  width: 100%;
}
.box2{
  background-color: #5900ff;
  height: 100vh;
  width: 100%;
}
 
image.thumb.png.aff8ff7701c2f761b3bae2c0488ca7c5.png
 
Link to comment
Share on other sites

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 Stackblitz that demonstrates 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 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

 

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

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