Vue 3 composable for accurate TOC/sidebar active link tracking without Intersection Observer compromises. Current stable version 1.1.3 (released 2024). Zero runtime dependencies, ships TypeScript types. Unlike typical Intersection Observer solutions, it implements a custom scroll observer that reliably highlights clicked links that never intersect, handles first/last link at page boundaries, and works consistently across scroll speeds, smooth scrolling, and hash navigation. Supports template refs or DOM elements in place of IDs, customizable offsets per scroll direction, and custom scroll containers. Does not scroll to targets or manipulate DOM. Released on npm with monthly cadence.
npm install vue-use-active-scrollVerified import paths — ran on the pinned version, not inferred.
Basic example: track active section based on scroll position and highlight a sidebar link accordingly.
Add scrollBehavior(to) { if (to.hash) return { el: to.hash } } to your Vue Router instance.Add 'html { scroll-behavior: smooth; }' in your global CSS.No action needed if using string IDs. If using refs, ensure they are valid TemplateRef or HTMLElement.
Access activeId.value in script setup or composition functions.
Import useActiveScroll and destructure isActive from its return, or upgrade to >=1.1.1.
Add scrollBehavior(to) { if (to.hash) return { el: to.hash } } to createRouter({...}).Use import { useActiveScroll } from 'vue-use-active-scroll' instead of import useActiveScroll from 'vue-use-active-scroll'.Run npm install vue-use-active-scroll (or pnpm/yarn/bun add) and ensure tsconfig includes node_modules/@types.
No dependency data recorded yet.