Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anchor-hash-scroll

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchor-hash-scroll

Anchor hash link scroll tracking and smooth scrolling

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
decreased by-8.11%
Maintainers
2
Weekly downloads
 
Created
Source

anchor-hash-scroll

Demo

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.

Install

With npm

npm install --save anchor-hash-scroll
const scroll = require('anchor-hash-scroll')
scroll({
  offset: 32, // Amount of top padding for each section
  duration: 1500  // Milliseconds for the smooth scroll
})

Using a CDN

You can use unpkg with the URL: unpkg.com/anchor-hash-scroll/dist/build.min.js

<script src='//unpkg.com/anchor-hash-scroll/dist/build.min.js'></script>

Usage

For the NPM version, you can pass in configuration when you initialize it:

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

When using via the CDN, you can configure it by using the global window.anchorHashScroll object:

window.anchorHashScroll.config({
  duration: 3000,
  offset: 0
})

Browser compatibility

This module uses addEventListener and querySelector, and no other modern features. Jump.js supports IE10+

Development

Build the distributions and example with npm run build-all

Run the example with something like npm install -g serve && serve docs

Lint the code with npm run lint

Keywords

FAQs

Package last updated on 02 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc