Simple Scrollspy

Simple Scrollspy

Simple scrollspy without jQuery, no dependencies and lightweight. 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'
})

<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

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

License

MIT License


Copyright (c) 2018 Kim Nguyen Huu


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Nguyen Huu Kim <kimnguyen.ict@gmail.com>