Jump to content
Search Community

elements layer messed up, index issue?

psfortuna test
Moderator Tag

Recommended Posts

I'm a beginner with GSAP and following a tutorial in a video, so i already got what I wanted, the issue is when I click my hamburger menu the layer or the object that was used together with GSAP is always on top with other elements, even a simple box can go over to the top without any z-index manipulation, idk please help me.. 
as you can see to opened hamburger menu, its still showing up even i dont intend to.

Unopened hamburger menu:
image.thumb.png.cadfc427b40d0a47293a3d9a6323b5c6.png


Opened hamburger menu:
image.thumb.png.a020d88cbe7d824a787ab95ae6544711.png

image.png




code:

 

import LogoImage from "../../common/Logo";
import DisplayPicture from "../../../assets/profile_in_pofolio-1.jpg";
import { useRef } from "react";
import "../main.scss";
const About = () => {
  const overlay = document.querySelector(".overlay");
 
  window.addEventListener("mousemove", (e) => {
    const { clientX, clientY } = e;
    const x = Math.round((clientX / window.innerWidth) * 100);
    const y = Math.round((clientY / window.innerHeight) * 100);
 
    gsap.to(overlay, {
      "--x": `${x}%`,
      "--y": `${y}%`,
      duration: 0.3,
      ease: "sine.out",
    });
  });
 
  // span.addEventListener("click", () => {
  //   overlay.classList.toggle("is-open");
  // });
 
  return (
    <>
      <div className="bg-c_Black w-screen h-screen flex items-center justify-center">
        <div className=" px-6 font-poppins bg-c_Black">
          <div className="md:flex justify-center items-center">
            <div className="text-center font-medium text-4xl md:text-6xl text-c_Orange flex flex-col space-y-6">
              <span>
                The most <span className="">Knowledgeable Experience </span>is
                the <br className="sm:hidden" />
                <span className="text-c_Orange">Experience</span> that has
                <span className="text-c_Orange"> Failure</span>.
              </span>
              <span>
                Not the <span className="text-c_Orange">Experience</span> full
                of <span className="text-c_Orange">Perfection</span>
                <br className="sm:hidden" /> and Immediate{" "}
                <br className="sm:hidden" />
                <span className="">Success</span>.
              </span>
            </div>
          </div>
        </div>
 
        <div className="overlay px-96 font-poppins bg-c_Orange absolute z-0">
          <div className="md:flex justify-center items-center">
            <div className="text-center font-bold text-4xl text-c_Black md:text-8xl flex flex-col space-y-6">
              <div className="text-center font-medium text-4xl md:text-6xl flex flex-col space-y-6">
                <span>
                  The most <span className="">Knowledgeable Experience </span>is
                  the <br className="sm:hidden" />
                  <span className="text-c_White">Experience</span> that has
                  <span className="text-c_White"> Failure</span>.
                </span>
                <span>
                  Not the <span className="text-c_White">Experience</span> full
                  of <span className="text-c_White">Perfection</span>
                  <br className="sm:hidden" /> and Immediate{" "}
                  <br className="sm:hidden" />
                  <span className="">Success</span>.
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </>
  );
};
 
export default About;
 

See the Pen by (@) on CodePen

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

  • Like 1
Link to comment
Share on other sites

Hi,

 

A few things.

 

It seems that you're using React in this example. Always use GSAP Context when adding GSAP animations in your react environments:

https://greensock.com/docs/v3/GSAP/gsap.context()

 

Also take a look at the resources in this page:

 

For your mouse follower I'd suggest using GSAP QuickTo:

https://greensock.com/docs/v3/GSAP/gsap.quickTo()

 

Finally this could be resolved by setting the visibility to hidden when the menu animation is completed (hence when the menu is visible) and setting the visibility to visible when you close the menu. You can use GSAP autoAlpha for that:

// Hide the element
gsap.set(element, { autoAlpha: 0 });

// Show the element
gsap.set(element, { autoAlpha: 1 });

Hopefully this helps.

Happy Tweening!

  • Like 1
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...