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?
You can divide the window.innerHeight by 2
window.scrollBy(0, window.innerHeight / 2);
scrollBy accepts value in pixels only.
1vh = 1/100 viewport height. So you can calculate it manually.
window.scrollBy(0, valueInVh * window.innerHeight/100);
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);