I have a webpage on which I would like to scroll to a certain element.
That part works fine by using scrollIntoView
; but I would like to add a bit of space
Another potential solution is to scroll not the the element itself, but to one of its previous siblings. Example:
let elementToScrollTo = ;
const childOffset = 3;
for (let i = 0; i < childOffset; i++) {
if (!elementToScrollTo.previousElementSibling) {
break;
}
elementToScrollTo = elementToScrollTo.previousElementSibling;
}
elementToScrollTo.scrollIntoView();