@axn/backtotop

1.0.1 • Public • Published

BackToTop

BackToTop is a package with no dependencies to make simple "back to top" buttons.

Table of Contents

Install

Installing with npm:

npm i @axn/backtotop

Usage

BackToTop makes use of ESM exports. Most bundlers can import the module directly like so:

import * as BackToTop from '@axn/backtotop';

const element = document.querySelector('#back-to-top');
const button = BackToTop.applyToElement(element, {
    animationInDuration: 1000
});

// Destroy BackToTop when you're done
button.destroy();

For a full example, see floating-button.html.

Docs

applyToElement(element, [options]) {#docs-applytoelement}

Enables BackToTop events on an element.

  • element The element to apply BackToTop to.
  • options optional
    • yThreshold optional Minimum scroll position in pixels before element appears.
    • animationInDuration optional Duration of fade-in animation in milliseconds.
    • animationOutDuration optional Duration of fade-out animation in milliseconds.
    • scrollBehavior optional Scrolling method to use. Possible values: auto, instant, smooth.
    • animationIn optional Fade-in animation name.
    • animationOut optional Fade-out animation name.

Note

When applyToElement() is first called, BackToTop injects it's own stylesheet inside <head> with ID backtotop-style. This is to provide the default fade-in and fade-out animations.

License

See LICENSE

Package Sidebar

Install

npm i @axn/backtotop

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

14.7 kB

Total Files

9

Last publish

Collaborators

  • axn