可以通过设置window.location.hash,滚动到锚点,然后执行window.scrollBy(0, -20)等操作。
window.location.hash
window.scrollBy(0, -20)