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
+38-30Lines changed: 38 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,14 +16,14 @@ But it may not be the one-size-fits-all solution to highlight menu/sidebar links
16
16
17
17
You may noticed that's tricky to customize behavior according to different interactions.
18
18
19
-
For example, you want to immediately highlight targets when scroll is originated from click/navigation but not when it is originated from wheel/touch. You want also to highlight any clicked link even if it will never intersect.
19
+
For example, you want to immediately highlight targets when scroll is originated from click/navigation but not when it is originated from wheel/touch. You also want to highlight any clicked link even if it will never intersect.
20
20
21
-
**Vue Use Active Scroll** implements a custom scroll observer which automatically adapts to different interactions and always returns the "correct" active target.
21
+
**Vue Use Active Scroll** implements a custom scroll observer which automatically adapts to any type of scroll behaviors and interactions and always returns the "correct" active target.
| setActive |`(id: string) => void`|:firecracker: Function to include in your click handler to ensure adaptive behavior between any interaction that may cancel or resume scroll. |
172
-
| isActive |`(id: string) => boolean`| Whether the given Id is active or not |
173
-
| activeId |`Ref<string>`| Id of the active target |
174
-
| activeIndex |`Ref<number>`| Index of the active target in offset order, `0` for the first target and so on. |
You might noticed that if you have a fixed header and defined an `overlayHeight`, once you click to scroll to a target it may be underneath the header. You must set`scroll-margin-top` to your targets:
356
+
You might noticed that if you have a fixed header and defined an `overlayHeight`, once you click to scroll to a target it may be underneath the header. You must add`scroll-margin-top` to your targets:
If using Nuxt, Vue Router is already configured to scroll to the URL hash on page load or back/forward navigation.
372
+
> :warning:If using Nuxt 3, Vue Router is already configured to scroll to and from URL hash on page load or back/forward navigation. **So you don't need to do follow the steps below**. Otherwise rules must be defined manually.
373
373
374
-
If not using Nuxt and you're setting up Vue Router from scratch, you must enable the feature manually.
374
+
### Scrolling to hash
375
375
376
-
### Window
376
+
For content scrolled by the window, simply return the target element. To scroll to a target scrolled by a container, use _scrollIntoView_ method.
> :bulb: There's need to define _smooth_ or _auto_ here. Adding the [CSS rule](#2-define-scroll-behavior) is enough. Same applies below.
398
+
> :bulb: There's no need to define _smooth_ or _auto_ here. Adding the [CSS rule](#2-define-scroll-behavior) is enough.
393
399
394
-
### Container
400
+
> :bulb: There's no need need to set overlayHeight if using `scrollIntoView` as the method is aware of target's `scroll-margin-top` property.
395
401
396
-
To scroll to a target scrolled by a container, you must use `scrollIntoView`:
402
+
### Scrolling from hash to the top of the page
403
+
404
+
To navigate back to the top of the same page (e.g. clicking on browser back button from a hash to the page root), use the _scroll_ method for containers and return _top_ for content scrolled by the window.
0 commit comments