Search by

avalynx / avalynx-scrolltotop

jschwind

AvalynxScrollToTop is a simple, lightweight, and customizable scroll-to-top button component. Based on Bootstrap >=5.3 without any framework dependencies.

Package info

github.com/avalynx/avalynx-scrolltotop

Language:JavaScript

pkg:composer/avalynx/avalynx-scrolltotop

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-12-02 16:15 UTC

This package is auto-updated.

Last update: 2026-12-02 17:42:53 UTC


README

npm version npm downloads Composer version Composer downloads jsDelivr License Tests codecov GitHub stars

AvalynxScrollToTop is a simple, lightweight, and customizable scroll-to-top button component. It is based on Bootstrap (version 5.3 or higher) and does not require any other framework dependencies.

Features

  • Flexible Positioning: Place the button at bottom-right, bottom-left, top-right or top-left.
  • Container Support: Attach the button to the page (position: fixed) or to any scrollable container (position: sticky).
  • Smooth Scrolling: Scrolls back to the top with native smooth scroll behavior (can be disabled).
  • Custom Icons: Use the default SVG arrow or any icon markup (e.g. Font Awesome). The markup is sanitized to prevent XSS.
  • Optional Theme: A square, sharp-cornered theme stylesheet that takes its colors from Bootstrap variables and supports light and dark mode.
  • Accessible: Configurable aria-label and a visible focus ring.

Examples

Here is an overview of various use cases for AvalynxScrollToTop:

Installation

To use AvalynxScrollToTop in your project, you can directly include it in your HTML file. Ensure you have Bootstrap 5.3 or higher included in your project for AvalynxScrollToTop to work correctly.

First, include Bootstrap:

<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/js/bootstrap.bundle.min.js"></script>

Then, include AvalynxScrollToTop:

<link href="path/to/avalynx-scrolltotop.css" rel="stylesheet">
<script src="path/to/avalynx-scrolltotop.js"></script>

Replace path/to/avalynx-scrolltotop.js and path/to/avalynx-scrolltotop.css with the actual path to the files in your project. The stylesheet is the optional theme; without it, the button uses the Bootstrap classes from the className option.

Installation via jsDelivr (Link)

AvalynxScrollToTop is also available via jsDelivr. You can include it in your project like this:

<link href="https://cdn.jsdelivr.net/npm/avalynx-scrolltotop@1.0.2/dist/css/avalynx-scrolltotop.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/avalynx-scrolltotop@1.0.2/dist/js/avalynx-scrolltotop.js"></script>

Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxScrollToTop displays correctly.

Installation via NPM (Link)

AvalynxScrollToTop is also available as a npm package. You can add it to your project with the following command:

npm install avalynx-scrolltotop

After installing, you can import AvalynxScrollToTop into your JavaScript file like this:

import { AvalynxScrollToTop } from 'avalynx-scrolltotop';
import 'avalynx-scrolltotop/dist/css/avalynx-scrolltotop.css';

Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxScrollToTop displays correctly.

Installation via Symfony AssetMapper

php bin/console importmap:require avalynx-scrolltotop

After installing, you can import AvalynxScrollToTop into your JavaScript file like this:

import { AvalynxScrollToTop } from 'avalynx-scrolltotop';
import 'avalynx-scrolltotop/dist/css/avalynx-scrolltotop.css';

Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxScrollToTop displays correctly.

Installation via Symfony AssetComposer

More information about the Symfony AssetComposer Bundle can be found here.

{% do addAssetComposer('avalynx/avalynx-scrolltotop/dist/css/avalynx-scrolltotop.css') %}
{% do addAssetComposer('avalynx/avalynx-scrolltotop/dist/js/avalynx-scrolltotop.js') %}

Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxScrollToTop displays correctly.

Installation via Composer (Link)

AvalynxScrollToTop is also available as a Composer package. You can add it to your project with the following command:

composer require avalynx/avalynx-scrolltotop

After installing, you can import AvalynxScrollToTop into your HTML file like this:

<link href="vendor/avalynx/avalynx-scrolltotop/dist/css/avalynx-scrolltotop.css" rel="stylesheet">
<script src="vendor/avalynx/avalynx-scrolltotop/dist/js/avalynx-scrolltotop.js"></script>

Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxScrollToTop displays correctly.

Usage

To create a scroll-to-top button for the page, simply instantiate a new AvalynxScrollToTop object:

new AvalynxScrollToTop();

With custom options:

new AvalynxScrollToTop('body', {
    scrollTrigger: 200,
    position: 'bottom-left',
    className: 'btn btn-dark shadow-sm',
    smoothScroll: true
});

For a scrollable container:

new AvalynxScrollToTop('#my-scrollable-container', {
    scrollTrigger: 50,
    position: 'bottom-right'
});

Theme

The optional stylesheet avalynx-scrolltotop.css renders a square, sharp-cornered button. Its colors come from Bootstrap variables (--bs-primary, --bs-btn-*) and can be overridden with real values:

button.avalynx-scrolltotop {
    --avalynx-scrolltotop-color: #ffffff;
    --avalynx-scrolltotop-bg: #a42636;
    --avalynx-scrolltotop-bg-hover: #8b202e;
    --avalynx-scrolltotop-bg-active: #831e2b;
    --avalynx-scrolltotop-focus-ring: rgba(164, 38, 54, 0.35);
}

Options

AvalynxScrollToTop allows the following options for customization:

  • selector: (string) The CSS selector for the container element (default: 'body').
  • options: An object containing the following keys:
    • scrollTrigger: (number) The scroll position (in pixels) that triggers the button visibility (default: 100).
    • smoothScroll: (boolean) Whether scrolling back to the top should be smooth (default: true).
    • position: (string) The position of the button. One of bottom-right, bottom-left, top-right, top-left (default: 'bottom-right').
    • className: (string) Additional CSS classes for the button (default: 'btn btn-primary').
    • icon: (string) The icon markup. Scripts, event-handler attributes, javascript: URLs and embedded/browsing elements are stripped (default: SVG arrow-up).
    • ariaLabel: (string) The aria-label of the button (default: 'Scroll to top').
    • zIndex: (string) The z-index of the button (default: '1000').

Contributing

Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request with your changes or improvements. We're looking for contributions in the following areas:

  • Bug fixes
  • Feature enhancements
  • Documentation improvements

Before submitting your pull request, please ensure your changes are well-documented and follow the existing coding style of the project.

License

AvalynxScrollToTop is open-sourced software licensed under the MIT license.

Contact

If you have any questions, feature requests, or issues, please open an issue on our GitHub repository or submit a pull request.

Thank you for considering AvalynxScrollToTop for your project!