Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

64
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda