yutakahoulette-zz / anchor-hash-scroll

Anchor hash link scroll tracking and smooth scrolling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

anchor-scroll-hash

Features:

  • Finds all anchor links and their corresponding targets on a page and tracks scrolling, setting data-active attributes to true for links and targets within the current scroll.
  • Customizable smooth scrolling using jump.js.
  • Uses pushState to keep track of anchor jumping history.
  • Supports dynamic page layouts (elements changing height after ajax, etc...).

See jump.js smooth scrolling options here.

Example:

const anchorScroll = require('anchor-scroll-hash')
// takes options for smooth scrolling (jump.js)
anchorScroll({
  duration: 3000
, offset: 0 - document.querySelector('#topNav').offsetHeight
})

This uses addEventListener, and querySelector so may not work in old browsers unless you add polyfills.

About

Anchor hash link scroll tracking and smooth scrolling


Languages

Language:JavaScript 100.0%