Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

61
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!