> For the complete documentation index, see [llms.txt](https://anjia1.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anjia1.gitbook.io/web/browser/code/scrolltop.md).

# 设置页面滚动条

```javascript
// 回到顶部
const top = 0
```

```javascript
// 回到底部
const top = document.documentElement.scrollHeight - 
            document.documentElement.clientHeight
```

```js
// 设置：滚动条的 top
document.documentElement.scrollTop = top
document.body.scrollTop = top
```

```javascript
// 获取：滚动条的 top
return document.body.scrollTop || 
       document.documentElement.scrollTop || 
       0
```
