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

62
Vistas
window.pageOffsetY controlling an element on page

I am wondering if somebody can please explain how can I "target" different values of the pageOffesetY when the viewer scrolls?

Context: I am trying to create a simple website. When the user scrolls to some extent (wheel down like 3 times) -> an element (image) appears from the right to the center of the page. So far so good, I got a code running that works. Looks like this :

const square = document.querySelector('.square');

window.addEventListener('scroll', () => {
    const scrolled = window.pageYOffset;
    const val = scrolled * 0.5;
    square.style.transform = `translateX(${0.45 * val}%)`;
    square.style.borderRadius = `${0.025 * val}%`;
    square.style.height = `${0.1 * val}px`;
    square.style.width = `${0.1 * val}px`;
});

However, what I want to create is sort of a "break point", where if the user scrolls to (e.g. middle of the 1st section), the object then starts to move vertically (not horizontally via TranslateX property).

How can you actively controll WHAT happends depending on WHERE the scroll is? (I am assuming it has to do with the PageOffsetY value).

Thank you very much in advance!

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