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

184
Views
Javascript scroll down by vh

If I want to use this JavaScript command:

window.scrollBy(0,50);

It scrolls 50px down the page.

Is there a simple equivalent to scroll 50vh down the page? This doesn't work

window.scrollBy(0,50vh);

I saw this question here but is there a simpler way to do it?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can divide the window.innerHeight by 2

window.scrollBy(0, window.innerHeight / 2);
about 4 years ago · Santiago Trujillo Report

0

scrollBy accepts value in pixels only.

1vh = 1/100 viewport height. So you can calculate it manually.

window.scrollBy(0, valueInVh * window.innerHeight/100);
about 4 years ago · Santiago Trujillo Report

0

AFAIK the JavaScript DOM APIs only give you pixel values. If you want "50vh" in pixels you can easily calculate it yourself:

// height in pixel
const height = window.innerHeight;
const vhPixels = height * 0.5

window.scrollBy(0, vhPixels);
about 4 years ago · Santiago Trujillo Report
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!