How do you scroll a set number of pixels past an object?

Viewed 44

Suppose I wanted to scroll to an object, but I wanted it to go, say, 50 pixels further. I know the following would work:

document.getElementById("foo").scrollIntoView();
document.documentElement.scrollTop += 50;

But that looks a bit bodgy. It's hard to read, and I suspect it will run slightly slower, as it's scrolling twice instead of once.

Is there a one-liner that does the same thing? Something like

document.documentElement.scrollTop = document.getElementById("foo").fooDistance + 50;

I know fooDistance is wrong. What's the correct version?

I tried looking on this list but couldn't see anything that looked right.

1 Answers
Related