我有一个网页,希望滚动到特定的元素。
使用scrollIntoView
可以实现这一点;但是我想在该元素上方添加一些空间(20px
或其他值)。
我目前正在执行以下操作:
const moveToBlue = () => {
const blue = document.getElementById('blue')
blue.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start'});
};
我想要将页面再向上滚动20px(请参见我的演示)
这是否可能?