{"id":16237196,"url":"https://github.com/jeremenichelli/scrollprogress","last_synced_at":"2025-04-08T08:42:47.350Z","repository":{"id":771367,"uuid":"19671931","full_name":"jeremenichelli/scrollProgress","owner":"jeremenichelli","description":"🛸 Light weight library to observe the viewport scroll position","archived":false,"fork":false,"pushed_at":"2022-04-01T17:37:22.000Z","size":64,"stargazers_count":155,"open_issues_count":2,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-18T19:40:36.382Z","etag":null,"topics":["component","observer","progress","scroll","scrollbar","ui"],"latest_commit_sha":null,"homepage":"https://jeremenichelli.github.io/scrollProgress","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeremenichelli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-11T17:02:38.000Z","updated_at":"2024-05-23T11:43:32.000Z","dependencies_parsed_at":"2022-08-06T10:00:48.810Z","dependency_job_id":null,"html_url":"https://github.com/jeremenichelli/scrollProgress","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremenichelli%2FscrollProgress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremenichelli%2FscrollProgress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremenichelli%2FscrollProgress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeremenichelli%2FscrollProgress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeremenichelli","download_url":"https://codeload.github.com/jeremenichelli/scrollProgress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247807431,"owners_count":20999542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component","observer","progress","scroll","scrollbar","ui"],"created_at":"2024-10-10T13:34:53.429Z","updated_at":"2025-04-08T08:42:47.300Z","avatar_url":"https://github.com/jeremenichelli.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scrollProgress [![Build Status](https://travis-ci.org/jeremenichelli/scrollProgress.svg)](https://travis-ci.org/jeremenichelli/scrollProgress)\n\nLight weight library to observe the viewport scroll position.\n\nIn 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.\n\n**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.\n\n\n## Add it to your project\n\nInclude the `dist` file in a script tag or run `npm install scrollprogress --save`.\n\n\n## Use\n\nIn 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.\n\n```js\nimport ScrollProgress from 'scrollprogress';\n\nconst progressObserver = new ScrollProgress((x, y) =\u003e {\n  console.log(x, y);\n});\n```\n\nThe 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.\n\nThe method you pass will also get called on resize since the viewport and body metrics might change.\n\n### destroy\n\nWhenever you want the observer to stop working just call `progressObserver.destroy()`.\n\n\n## Recipes\n\n### Vanilla scroll progress bar\n\nTo 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.\n\n#### HTML\n\n```html\n\u003cdiv class=\"progress-bar\"\u003e\u003c/div\u003e\n```\n\n#### CSS\n\n```css\n.progress-bar {\n  background-color: rebeccapurple;\n  height: 5px;\n  position: fixed;\n  top: 0;\n  bottom: 0;\n}\n```\n\n#### JS\n\n```js\nconst progressElement = document.querySelector('.progress-bar');\n\nconst progressObserver = new ScrollProgress((x, y) =\u003e {\n  progressElement.style.width = y * 100 + '%';\n});\n```\n\nAnd that's it! Super simple.\n\n_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._\n\n\n### As a React component\n\nOne 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.\n\n```jsx\nimport { Component } from 'react';\nimport ScrollProgress from 'scrollprogress';\n\nexport default class ScrollProgress extends Component {\n  constructor() {\n    this.state = {\n      progress: 0\n    };\n  }\n\n  componentDidMount() {\n    this.progressObserver = new ScrollProgress((x, y) =\u003e {\n      this.setState({ progress: y * 100 });\n    });\n  }\n\n  componentWillUnmount() {\n    this.progressObserver.destroy();\n  }\n\n  render() {\n    const style = {\n      backgroundColor: 'rebeccapurple',\n      height: '5px',\n      position: 'fixed',\n      top: 0,\n      bottom: 0,\n      width: `${this.state.progress}%`\n    };\n\n    return (\n      \u003cdiv\n        className=\"progress-bar\"\n        style={ style }\n      /\u003e\n    );\n  }\n}\n```\n\nIt'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.\n\n## License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2017 Jeremias Menichelli\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremenichelli%2Fscrollprogress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremenichelli%2Fscrollprogress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremenichelli%2Fscrollprogress/lists"}