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

191
Vistas
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?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You can divide the window.innerHeight by 2

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

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);
over 4 years ago · Santiago Trujillo Denunciar

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);
over 4 years ago · Santiago Trujillo Denunciar
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