1.0.1 • Published 2 years ago
@axn/backtotop v1.0.1
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/backtotopUsage
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.
elementThe element to apply BackToTop to.optionsoptionalyThresholdoptional Minimum scroll position in pixels before element appears.animationInDurationoptional Duration of fade-in animation in milliseconds.animationOutDurationoptional Duration of fade-out animation in milliseconds.scrollBehavioroptional Scrolling method to use. Possible values:auto,instant,smooth.animationInoptional Fade-in animation name.animationOutoptional 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