Socket
Socket
Sign inDemoInstall

smooth-anchorate

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    smooth-anchorate

Smooth scrolling to anchor links.


Version published
Maintainers
1
Created

Readme

Source

smooth anchorate

Smooth Scroll to anchor links.

Smooth Scroll to anchor links with client-side routes e.g. with history's listen, React Router's onUpdate, or Gatsby's onRouteChange. Register a listener to call this and when window.location.hash isn't empty, it'll scrollIntoView first matching element by id or name per spec.

Originally based on: https://github.com/reactjs/react-router/issues/394#issuecomment-220221604

Install

npm install --save smooth-anchorate

Use

history

import { smoothAnchorate } from 'smooth-anchorate'
import { createHistory } from 'history'
 
const history = createHistory()

history.listen(() => {
  smoothAnchorate()
})

React Router

import { smoothAnchorate } from 'smooth-anchorate'
import { render } from 'react-dom'
import { Router, browserHistory } from 'react-router'

function onUpdate () {
  smoothAnchorate()
}

// ...

render((
  <Router
    onUpdate={onUpdate}
    history={browserHistory}
  />
), document.getElementById('app'))

Gatsby

In gastby-browser.js:

import { smoothAnchorate } from 'smooth-anchorate'

exports.onRouteChange = () => {
  smoothAnchorate()
}

FAQs

Last updated on 09 Mar 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc