You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-20Lines changed: 39 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
The [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) is a great API.
15
15
But it may not be the one-size-fits-all solution to highlight menu/sidebar links.
16
16
17
-
You may noticed that last targets, may never intersect if entirely visible in the viewport. Clicking on their links highlights other links or does nothing. In addition to that, the URL hash may not reflect the active link.
17
+
You may noticed that last targets may never intersect if entirely visible in the viewport. Clicking on their links highlights other links or does nothing. In addition to that, the URL hash may not reflect the active link.
18
18
19
19
But also, it's tricky to customize behavior according to different scroll interactions.
20
20
@@ -26,7 +26,7 @@ For example, you want to immediately highlight targets when scroll is originated
26
26
27
27
- Precise and stable at any speed
28
28
- CSS scroll-behavior and callback agnostic
29
-
- Adaptive behavior on mount (hash), scroll, click, cancel.
29
+
- Adaptive behavior on mount, back/forward navigation, scroll, click, cancel.
30
30
- Customizable boundary offsets for each direction
You're free to choose between CSS (smooth or auto), [scrollIntoView](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) or even a library like [animated-scroll-to](https://github.com/Stanko/animated-scroll-to).
212
+
213
+
#### A. Using CSS scroll-behavior
214
+
215
+
- If content is scrolled by the window, add the following CSS rule to your `html` element:
216
+
217
+
```css
204
218
html {
205
-
/* or .container { */
206
219
scroll-behavior: smooth; /* or 'auto' */
207
220
}
208
-
</style>
209
221
```
210
222
211
-
Feel free to create your own click handler and to choose the scrolling strategy: CSS (smooth or auto), [scrollIntoView](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) or even a library like [animated-scroll-to](https://github.com/Stanko/animated-scroll-to) with custom easings will work. Just remember to call `setActive` in your handler.
> :bulb: If you using native CSS scroll-behavior, [adding the rule](#define-scroll-behavior) to your CSS is enough. No need to set it again in Vue Router.
374
393
375
394
### Containers
376
395
377
-
The above rule will work if your content is scrolled by the window. If you want to scroll to a target inside a container, you must use `scrollIntoView`:
396
+
If you want to scroll to a target inside a container, you must use `scrollIntoView`:
0 commit comments