Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Why the event listener in GSAP gets the variables from the entire with of the screen rather than just the inner portion?

I'm developing a website with a maximum resolution of 1200px that gets entered to make sure that the content looks good on bigger screens. Now I'm stuck with a problem, I'm creating an animation with GSAP on hover with a series of shapes that follow the user, however the animation it's "offset" as GSAP take in consideration the entire width of the viewport rather than the fixed content size:

<main>
      <section>
            <div class="shapes">
                <div class="shape shape-1"></div>
                <div class="shape shape-2"></div>
                <div class="shape shape-3"></div>
                <div class="shape shape-4"></div>
            </div>
            <div class="content">
              <h1>Hello! Some text</h1>
            </div>
      </section>
</main>

CSS:

section {
  max-width: 1200px;
  margin: 0 auto;
  display: block;
  padding: 0px 20px;
}

.shapes {
    position: relative;
    height: 100vh;
    max-width: 1200px;
    background: white;
    overflow: hidden;
}

.shape {
    will-change: transform;
    position: absolute;
    border-radius: 50%;
    
    $shapes: (#63A088: 600px, #56638A: 300px, #483A58: 100px);
    
    @each $color, $size in $shapes {
      &.shape-#{index($shapes, ($color $size))} {
        background: $color;
        width: $size;
        height: $size;
        margin: (-$size/2) 0 0 (-$size/2);
      }
    }
}

.content {
    top: 0;
    left: 0;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    max-width: 1200px;
    background: white;
    mix-blend-mode: screen;
  }
  
.h1 {   
    color:black;
    margin: 0;
    text-align: center;
}

JS

window.addEventListener('mousemove', (e) => {
  const { clientX, clientY } = e

    const mouseX = e.clientX;
    const mouseY = e.clientY;


//   const mouseX = Math.round((e.clientX / window.innerWidth) * 100);
//   const mouseY = Math.round((e.clientY / window.innerHeight) * 100);
        
    gsap.to(".shape", {
      x: mouseX,
      y: mouseY,
      stagger: -0.1
    })
})

I tried to add a specific class and target the section width, but unfortunately this solution doesn't work.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda