All Projects → jeremenichelli → Scrollprogress

jeremenichelli / Scrollprogress

Licence: mit
🛸 Light weight library to observe the viewport scroll position

Projects that are alternatives of or similar to Scrollprogress

Uos
🐭 A tiny 250b scroll listener with progress.
Stars: ✭ 349 (+135.81%)
Mutual labels:  observer, scroll, progress
React Scrollbars Custom
The best React custom scrollbars component
Stars: ✭ 576 (+289.19%)
Mutual labels:  component, scroll, scrollbar
V Bar
The virtual responsive crossbrowser scrollbar component for VueJS 2x
Stars: ✭ 216 (+45.95%)
Mutual labels:  component, scroll, scrollbar
React Scrolllock
🔒 Prevent scroll on the <body />
Stars: ✭ 393 (+165.54%)
Mutual labels:  component, scroll
Ngx Scrollbar
Custom overlay-scrollbars with native scrolling mechanism
Stars: ✭ 355 (+139.86%)
Mutual labels:  scroll, scrollbar
React Scrollspy
🔯 react scrollspy component
Stars: ✭ 382 (+158.11%)
Mutual labels:  component, scroll
scrollpup.js
Minimal beautiful bar to show scroll progress. Pure Javascript Plugin.MIT
Stars: ✭ 83 (-43.92%)
Mutual labels:  scroll, scrollbar
Vuebar
(🗃️ Archived) Vue 2 directive for custom scrollbar that uses native scroll behavior. Lightweight, performant, customizable and without dependencies. Used successfully in production on https://ggather.com
Stars: ✭ 650 (+339.19%)
Mutual labels:  scroll, scrollbar
React Progress Button
🌀 Simple react.js component for an inline progress indicator
Stars: ✭ 516 (+248.65%)
Mutual labels:  component, progress
Vue Step Progress
A simple Vue component that displays a Progress Bar with labels for each step
Stars: ✭ 26 (-82.43%)
Mutual labels:  component, progress
React Native Really Awesome Button
React Native button component. Awesome Button is a 3D at 60fps, progress enabled, social ready, extendable, production ready component that renders an awesome animated set of UI buttons. 📱
Stars: ✭ 988 (+567.57%)
Mutual labels:  component, progress
React Awesome Button
React button component. Awesome button is a 3D UI, progress, social and share enabled, animated at 60fps, light weight, performant, production ready react UI button component. 🖥️ 📱
Stars: ✭ 943 (+537.16%)
Mutual labels:  component, progress
Vuescroll
A customizable scrollbar plugin based on vue.js for PC , mobile phone, touch screen, laptop.
Stars: ✭ 1,016 (+586.49%)
Mutual labels:  component, scrollbar
Fakescroll
vanilla-js lightweight custom HTML scrollbar
Stars: ✭ 309 (+108.78%)
Mutual labels:  component, scrollbar
Vue Simple Spinner
A simple, flexible spinner for Vue.js
Stars: ✭ 385 (+160.14%)
Mutual labels:  component, progress
uot
🦁 A tiny setTimeout alternative with progress.
Stars: ✭ 43 (-70.95%)
Mutual labels:  observer, progress
React Scroll Parallax
🔮 React components to create parallax scroll effects for banners, images or any other DOM elements
Stars: ✭ 1,699 (+1047.97%)
Mutual labels:  component, scroll
react-is-scrolling
Simply detect if users are scrolling in your components in a declarative API
Stars: ✭ 17 (-88.51%)
Mutual labels:  scroll, scrollbar
Awloader
AWLoader is a UI Component that allows you to integrate loader that fits your needs within your app.
Stars: ✭ 11 (-92.57%)
Mutual labels:  component, progress
Vue Gemini Scrollbar
Custom overlay-scrollbars with native scrolling mechanism for web applications基于原生滚动机制的自定义滚动条
Stars: ✭ 99 (-33.11%)
Mutual labels:  scroll, scrollbar

scrollProgress Build Status

Light weight library to observe the viewport scroll position.

In previous versions this package injected a scroll bar showing the scrolling progress. Why did I change it? Because it wasn't flexible to be adapted to others uses or UI libraries.

This means you still can create a progress bar as before and even with less code, keep scrolling to the Recipes section to see how.

Add it to your project

Include the dist file in a script tag or run npm install scrollprogress --save.

Use

In this last version, you have to create a new instance to create an observer and pass a callback to the contructor. That observer can be destroy at any time.

import ScrollProgress from 'scrollprogress';

const progressObserver = new ScrollProgress((x, y) => {
  console.log(x, y);
});

The callback will get two arguments, the first one being a decimal number for the horizontal scrolling progress and the second one for the vertical scrolling progress.

The method you pass will also get called on resize since the viewport and body metrics might change.

destroy

Whenever you want the observer to stop working just call progressObserver.destroy().

Recipes

Vanilla scroll progress bar

To accomplish the old functionality you will need to add the DOM element and the styles, something that the old version did for you, and then create an observer to update the bar width.

HTML

<div class="progress-bar"></div>

CSS

.progress-bar {
  background-color: rebeccapurple;
  height: 5px;
  position: fixed;
  top: 0;
  bottom: 0;
}

JS

const progressElement = document.querySelector('.progress-bar');

const progressObserver = new ScrollProgress((x, y) => {
  progressElement.style.width = y * 100 + '%';
});

And that's it! Super simple.

Remember the only thing that the script will control will be the width of the progress bar as you scroll, the rest of the styling is all on you.

As a React component

One of the main reasons this library was moved to this new approach is because you can easily couple an observer with any component library used nowadays. For example, create a React scroll bar component.

import { Component } from 'react';
import ScrollProgress from 'scrollprogress';

export default class ScrollProgress extends Component {
  constructor() {
    this.state = {
      progress: 0
    };
  }

  componentDidMount() {
    this.progressObserver = new ScrollProgress((x, y) => {
      this.setState({ progress: y * 100 });
    });
  }

  componentWillUnmount() {
    this.progressObserver.destroy();
  }

  render() {
    const style = {
      backgroundColor: 'rebeccapurple',
      height: '5px',
      position: 'fixed',
      top: 0,
      bottom: 0,
      width: `${this.state.progress}%`
    };

    return (
      <div
        className="progress-bar"
        style={ style }
      />
    );
  }
}

It's easy to imagine how to create the same component for other frameworks. If you want to add a recipe or any other use case to the documentation clone this repo and make a pull request.

License

The MIT License (MIT)

Copyright (c) 2017 Jeremias Menichelli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].