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

react-scrollspy-pure

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-scrollspy-pure

A react component provides the scrollspy feature with Intersection Observer API

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-scrollspy-pure

NPM

About

A react component provides the scrollspy feature with Intersection Observer API

Install

use yarn

yarn add react-scrollspy-pure

OR

use npm

npm install --save react-scrollspy-pure

Props

NameTypeDefaultoptionsDescription
WrapperComponentPropTypes.node'main'
sectionElementNamePropTypes.node'section'
activeClassNamestring'active'
activeClassToenum'parent''parnet', 'self'
navSelectorelementdocument
navItemSelectorstring / function'nav li a'
intersectionRationumber0.5between 0 to 1
optionsobjectnull

Usage

import React from 'react';
import ScrollSpy from 'react-scrollspy-pure';

export default function App() {
  const navRef = React.useRef();
  return (
    <div>
      <nav ref={navRef}>
        <ol>
          <li><a href="#home">Home</a></li>
          <li><a href="#about">About</a></li>
          <li><a href="#articles">Articles</a>
            <ul>
              <li><a href="#article-a">Article A</a></li>
              <li><a href="#article-b">Article B</a></li>
              <li><a href="#article-c">Article C</a></li>
            </ul>
          </li>
          <li><a href="#links">Links</a></li>
          <li><a href="#contact">Contact</a></li>
        </ol>
      </nav>
      <ScrollSpy navSelector={navRef.current}>
        <section id="home">
          <h2>Home</h2>
        </section>
        <section id="about">
          <h2>About</h2>
        </section>
        <section id="articles">
          <h2>Articles</h2>
          <section id="article-a">
            <h2>Article A</h2>
          </section>
          <section id="article-b">
            <h2>Article B</h2>
          </section>
          <section id="article-c">
            <h2>Article C</h2>
          </section>
        </section>
        <section id="links">
          <h2>Links</h2>
        </section>
        <section id="contact">
          <h2>Contact</h2>
        </section>
      </ScrollSpy>
    </div>
  );
}

Suggestion

Apply smooth scroll behavior

html {
	scroll-behavior: smooth;
}

License

MIT © mingkin123

FAQs

Package last updated on 25 Jun 2020

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