Simple scrollspy without jQuery, no dependencies
Switch branches/tags
Nothing to show
Clone or download
Latest commit ae335f2 Apr 1, 2018
Permalink
Failed to load latest commit information.
demo Fix github page Mar 31, 2018
dist Fix typo Mar 31, 2018
src Fix typo Mar 31, 2018
.gitignore Create Simple Scrollspy Mar 31, 2018
.npmignore Fix github page Mar 31, 2018
LICENSE Initial commit Mar 31, 2018
README.md Fix github page Mar 31, 2018
_config.yml Fix github page Mar 31, 2018
package.json Fix typo Mar 31, 2018
webpack.config.js Fix github page Mar 31, 2018
yarn.lock Create Simple Scrollspy Mar 31, 2018

README.md

Simple Scrollspy

Simple scrollspy is lightweight javascript library without jQuery, no dependencies. Only 1.94Kb. This is a demo.

Install

You can install by npm or download inject simple-scrollspy.js file into your HTML code:

npm install simple-scrollspy
<script src="/path/to/dist/simple-scrollspy.js"></script>

Usages

import scrollSpy from 'simple-scrollspy'

scrollSpy('#menu-list', {
    offset: 100,
    menuActiveTarget: '.menu__item > a',
    sectionClass: 'body section.scrollspy',
    activeClass: 'active'
})

Or:

<script src="/path/to/dist/simple-scrollspy.js"></script>
<script>
    window.onload = function () {
        scrollSpy('#menu-list', {
            offset: 100,
            menuActiveTarget: '.menu__item > a',
            sectionClass: 'body section.scrollspy',
            activeClass: 'active'
        })
    }
</script>

Arguments

  • The first argument is your menu list selector. Type of String|HTMLElement.
  • The second argument is optional. Type of Object:
Name Type Default Description
offset Number 0 Offset number
menuActiveTarget String li > a Element will be added active class
sectionClass String .scrollspy Query selector to your sections
activeClass String active Active class name

Helpful links

Licence

MIT