1.2.0 • Published 2 years ago

smooth-scroll-by v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Vanilla JS Scrolling

npm version npm.io

Demo

Browsers support

Better support in modern browsers | IE | Edge | Chrome | Safari | Opera | Firefox | UC Browser | | --- | --- | --- | --- | --- | --- | --- | | - | + | + | + | + | + | + |

Working with the library

# link
<a href="#section1">block 1</a>
# or
<button data-scroll-href="#section2">block 2</button>
# or
<button data-scroll-href="#section3" class="link">block 3</button>
# You can use both options

# Blocks should have id
<section id="section1">1</section>
<section id="section2">2</section>
<section id="section3">2</section>

To get started, download the npm i smooth-scroll-by library and import it into your project

js

import SmoothScroll from 'smooth-scroll-by';

new SmoothScroll();

CDN

JS

<script defer src="https://cdn.jsdelivr.net/npm/smooth-scroll-by@1.2.0/dist/index.js"></script>

HTML

<script>
    document.addEventListener('DOMContentLoaded', function() {
        new SmoothScroll('a[href*="#"]');
        // or new SmoothScroll('.link');
        // or new SmoothScroll('[data-scroll-href]');
    });
</script>

Parameters

If the page has a sticky menu, just add its class as the first parameter

new SmoothScroll('a[href*="#"]', {
    offsetTop: '.js-fix-header'
});

You can also set the scroll speed (default 600)

 new SmoothScroll('a[href*="#"]', {
    speed: 1000,
    offsetTop: '.js-fix-header'
});
1.2.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago