DEV Community

Sh Raj
Sh Raj

Posted on • Edited on • Originally published at github.com

Create Scroll Progress Indicator on blog/website

ScrollProgressJS Visitors


https://sh20raj.github.io/ScrollProgressJS/

GitHub logo SH20RAJ / ScrollProgressJS

ScrollProgressJS is a lightweight JavaScript library that creates a customizable scroll progress indicator for web pages. It allows you to display a visual progress bar indicating how much of the page has been scrolled.

ScrollProgressJS

Visitors

ScrollProgressJS is a lightweight JavaScript library that creates a customizable scroll progress indicator for web pages. It allows you to display a visual progress bar indicating how much of the page has been scrolled.

ScrollProgressJS Demo

Features

  • Customizable Progress Bar: Configure color, height, and position of the progress bar.
  • Auto-Initialization: Automatically initializes if data-autoload attribute is set.
  • Responsive: Adjusts dynamically as users scroll through the page.
  • Lightweight: Simple and efficient library with no external dependencies.

Installation

You can include ScrollProgressJS in your project via CDN, npm, or by downloading the script:

CDN

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ScrollProgressJS@main/ScrollProgress.js"></script>
Enter fullscreen mode Exit fullscreen mode

npm

npm install scroll-progress-indicator
Enter fullscreen mode Exit fullscreen mode

Download

Usage

Browser

Basic Initialization

To initialize ScrollProgressJS with default settings:

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ScrollProgressJS@main/ScrollProgress.js" data-autoload="true"></script>
Enter fullscreen mode Exit fullscreen mode

Advanced Configuration

You can also customize the progress bar…

ScrollProgressJS is a lightweight JavaScript library that creates a customizable scroll progress indicator for web pages. It allows you to display a visual progress bar indicating how much of the page has been scrolled.


ScrollProgressJS Demo

Features

  • Customizable Progress Bar: Configure color, height, and position of the progress bar.
  • Auto-Initialization: Automatically initializes if data-autoload attribute is set.
  • Responsive: Adjusts dynamically as users scroll through the page.
  • Lightweight: Simple and efficient library with no external dependencies.

Installation

You can include ScrollProgressJS in your project via CDN or by downloading the script:

CDN

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ScrollProgressJS@main/ScrollProgress.js"></script>
Enter fullscreen mode Exit fullscreen mode

Download

Usage

Basic Initialization

To initialize ScrollProgressJS with default settings:

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ScrollProgressJS@main/ScrollProgress.js" data-autoload="true"></script>
Enter fullscreen mode Exit fullscreen mode

Advanced Configuration

You can also customize the progress bar with your own configurations:

<script src="scrollprogress.js"></script>
<script>
  // Custom initialization
  ScrollProgress.init({
    color: '#ff5722',   // Progress bar color
    height: '4px',      // Progress bar height
    position: 'bottom'  // Progress bar position ('top' or 'bottom')
  });
</script>
Enter fullscreen mode Exit fullscreen mode

Updating Configuration

After initialization, you can update the configuration:

ScrollProgress.setConfig({
  color: '#4caf50',  // Updated color
  height: '2px',     // Updated height
  position: 'top'    // Updated position
});
Enter fullscreen mode Exit fullscreen mode

Destroying the Progress Bar

To remove the ScrollProgressJS and stop listening for scroll events:

ScrollProgress.destroy();
Enter fullscreen mode Exit fullscreen mode

Examples

Auto-Initialization

<!-- Auto-initialize with default settings -->
<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/ScrollProgressJS@main/ScrollProgress.js" data-autoload="true"></script>
Enter fullscreen mode Exit fullscreen mode

Custom Initialization

<!-- Custom initialization -->
<script src="scrollprogress.js"></script>
<script>
  ScrollProgress.init({
    color: '#007bff',   // Blue color
    height: '3px',      // 3px height
    position: 'bottom'  // Progress bar at the bottom
  });
</script>
Enter fullscreen mode Exit fullscreen mode

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Create a new Pull Request

Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Inspired by the need for a simple and customizable scroll progress indicator.
  • Built with ❤️ and JavaScript.

Contact

For issues, suggestions, or feedback, please create an issue.


Made with ❤️ by SH20RAJ

Top comments (0)