Skip to content

Commit da34ccd

Browse files
committed
docs: add behavior option to scrollBehavior
1 parent eafdcee commit da34ccd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: docs/guide/advanced/scroll-behavior.md

+15
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,18 @@ scrollBehavior (to, from, savedPosition) {
8080
```
8181

8282
It's possible to hook this up with events from a page-level transition component to make the scroll behavior play nicely with your page transitions, but due to the possible variance and complexity in use cases, we simply provide this primitive to enable specific userland implementations.
83+
84+
## Smooth Scrolling
85+
86+
You can enable native smooth scrolling for [browsers supporting it](https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions/behavior) by simply adding the `behavior` option to the object returned inside `scrollBehavior`:
87+
88+
```js
89+
scrollBehavior (to, from, savedPosition) {
90+
if (to.hash) {
91+
return {
92+
selector: to.hash
93+
behavior: 'smooth',
94+
}
95+
}
96+
}
97+
```

0 commit comments

Comments
 (0)