Skip to content

Commit d47deea

Browse files
committed
edit readme, comments
1 parent 7e98141 commit d47deea

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@
1414
The [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) is a great API.
1515
But it may not be the one-size-fits-all solution to highlight menu/sidebar links.
1616

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's tricky to customize behavior according to different interactions.
1818

19-
But also, it's tricky to customize behavior according to different scroll interactions.
20-
21-
For example, you want to immediately highlight targets when scroll is originated from click but not when scroll is originated from wheel/touch.
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.
2220

2321
**Vue Use Active Scroll** implements a custom scroll observer which automatically adapts to different interactions and always returns the "correct" active target.
2422

2523
### Features
2624

2725
- Precise and stable at any speed
2826
- CSS scroll-behavior and callback agnostic
29-
- Adaptive behavior on mount, back/forward navigation, scroll, click, cancel.
27+
- Adaptive behavior on mount, back/forward hash navigation, scroll, click, cancel.
3028
- Customizable boundary offsets for each direction
3129
- Customizable behavior on top/bottom reached
3230
- Supports containers different than window
@@ -168,12 +166,12 @@ const { isActive, setActive } = useActive(targets, {
168166

169167
### Return object
170168

171-
| Name | Type | Description |
172-
| ----------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
173-
| setActive | `(id: string) => void` | :firecracker: Function to include in your click handler to ensure adaptive behavior between any futher scroll/cancel interaction. |
174-
| isActive | `(id: string) => boolean` | Whether the given Id is active or not |
175-
| activeId | `Ref<string>` | Id of the active target |
176-
| activeIndex | `Ref<number>` | Index of the active target in offset order, `0` for the first target and so on. |
169+
| Name | Type | Description |
170+
| ----------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
171+
| 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. |
177175

178176
<br />
179177

@@ -369,11 +367,13 @@ useActive(targets, { overlayHeight: 100 })
369367

370368
<br />
371369

372-
## Vue Router scroll to hash on page mount
370+
## Vue Router scroll to hash on mount
371+
372+
If using Nuxt, Vue Router is already configured to scroll to the URL hash on page load or back/forward navigation.
373373

374-
If using Nuxt, Vue Router is already configured to scroll to the URL hash on page load, back/forward navigation.
374+
If not using Nuxt and you're setting up Vue Router from scratch, you must enable the feature manually.
375375

376-
If not using Nuxt and you're setting up Vue Router from scratch, you must enable the feature manually:
376+
### Window
377377

378378
```js
379379
const router = createRouter({
@@ -389,11 +389,11 @@ const router = createRouter({
389389
})
390390
```
391391

392-
> :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.
392+
> :bulb: There's need to define _smooth_ or _auto_ here. Adding the [CSS rule](#2-define-scroll-behavior) is enough. Same applies below.
393393
394-
### Containers
394+
### Container
395395

396-
If you want to scroll to a target inside a container, you must use `scrollIntoView`:
396+
To scroll to a target scrolled by a container, you must use `scrollIntoView`:
397397

398398
```js
399399
const router = createRouter({

src/useActive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,20 @@ export function useActive(
188188

189189
function onHashChange(event: HashChangeEvent) {
190190
if (matchMedia.value) {
191-
// If hash is not in the URL
191+
// If hash is not anymore in the URL
192192
if (!event.newURL.includes('#') && activeId.value) {
193193
const prevY = getSentinel();
194194

195195
requestAnimationFrame(() => {
196-
// If scrolled on its own reset activeId, if not keep current
196+
// If scrolled to top on its own, reset activeId
197197
const newY = getSentinel();
198198
if (prevY !== newY) {
199199
return (activeId.value = jumpToFirst ? ids.value[0] : '');
200200
}
201201
});
202202
}
203203

204-
// Else set it as active
204+
// Else set hash as active
205205
const hashId = getHashId();
206206
if (hashId) {
207207
activeId.value = hashId;

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { customRef, Ref } from 'vue';
1+
import { customRef, type Ref } from 'vue';
22

33
export const isSSR = typeof window === 'undefined';
44

0 commit comments

Comments
 (0)