首页 > 解决方案 > 为什么我的页面在重新加载时会向下滚动一点

问题描述

出于某种原因,当我重新加载页面时,它会向下滚动一点。原因是这段代码,但我不知道为什么。

<script>

window.scrollBy({
top: 100,
left: 0,
behavior: 'smooth'
});

</script>

这会强制一个小滚动吗?我认为它只是帮助链接。

标签: javascripthtmljavascript-objects

解决方案


这是来自 mdn 文档https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollBy

The Window.scrollBy() method scrolls the document in the window by the given amount.

所以是的,最高值将使您的窗口滚动 100px


推荐阅读