{"id":13452540,"url":"https://github.com/wessberg/scroll-behavior-polyfill","last_synced_at":"2025-04-07T13:07:28.055Z","repository":{"id":41374500,"uuid":"102880435","full_name":"wessberg/scroll-behavior-polyfill","owner":"wessberg","description":"A polyfill for the 'scroll-behavior' CSS-property","archived":false,"fork":false,"pushed_at":"2021-09-15T07:28:16.000Z","size":127,"stargazers_count":103,"open_issues_count":13,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T11:04:10.146Z","etag":null,"topics":["css","polyfill","scroll-behavior","smooth","smooth-scrolling"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/wessberg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-08T16:12:07.000Z","updated_at":"2024-12-17T20:17:15.000Z","dependencies_parsed_at":"2022-07-30T08:48:00.476Z","dependency_job_id":null,"html_url":"https://github.com/wessberg/scroll-behavior-polyfill","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fscroll-behavior-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fscroll-behavior-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fscroll-behavior-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fscroll-behavior-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wessberg","download_url":"https://codeload.github.com/wessberg/scroll-behavior-polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"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":["css","polyfill","scroll-behavior","smooth","smooth-scrolling"],"created_at":"2024-07-31T07:01:26.980Z","updated_at":"2025-04-07T13:07:28.037Z","avatar_url":"https://github.com/wessberg.png","language":"TypeScript","funding_links":["https://www.patreon.com/bePatron?u=11315442"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003c!-- SHADOW_SECTION_LOGO_START --\u003e\n\n\u003cdiv\u003e\u003cimg alt=\"Logo\" src=\"https://raw.githubusercontent.com/wessberg/scroll-behavior-polyfill/master/documentation/asset/logo.png\" height=\"60\"   /\u003e\u003c/div\u003e\n\n\u003c!-- SHADOW_SECTION_LOGO_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_START --\u003e\n\n\u003e A polyfill for the 'scroll-behavior' CSS-property\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_START --\u003e\n\n\u003ca href=\"https://npmcharts.com/compare/scroll-behavior-polyfill?minimal=true\"\u003e\u003cimg alt=\"Downloads per month\" src=\"https://img.shields.io/npm/dm/scroll-behavior-polyfill.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/scroll-behavior-polyfill\"\u003e\u003cimg alt=\"NPM version\" src=\"https://badge.fury.io/js/scroll-behavior-polyfill.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/wessberg/scroll-behavior-polyfill\"\u003e\u003cimg alt=\"Dependencies\" src=\"https://img.shields.io/david/wessberg%2Fscroll-behavior-polyfill.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wessberg/scroll-behavior-polyfill/graphs/contributors\"\u003e\u003cimg alt=\"Contributors\" src=\"https://img.shields.io/github/contributors/wessberg%2Fscroll-behavior-polyfill.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/prettier/prettier\"\u003e\u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Support on Patreon\" src=\"https://img.shields.io/badge/patreon-donate-green.svg\"    /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_START --\u003e\n\n## Description\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_END --\u003e\n\nThe [`scroll-behavior`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior) CSS-property as well as the extensions to the Element interface in the [CSSOM View Module](https://drafts.csswg.org/cssom-view/#dom-element-scrollto-options-options) CSS property sets the behavior for a scrolling box when scrolling is triggered by the navigation or CSSOM scrolling APIs.\nThis polyfill brings this new feature to all browsers.\n\nIt is very efficient, tiny, and works with the latest browser technologies such as Shadow DOM.\n\nThis polyfill also implements the extensions to the Element interface in the [CSSOM View Module](https://drafts.csswg.org/cssom-view/#dom-element-scrollto-options-options) such as `Element.prototype.scroll`, `Element.prototype.scrollTo`, `Element.protype.scrollBy`, and `Element.prototype.scrollIntoView`.\n\n\u003c!-- SHADOW_SECTION_FEATURES_START --\u003e\n\n### Features\n\n\u003c!-- SHADOW_SECTION_FEATURES_END --\u003e\n\n- Spec-compliant\n- Tiny\n- Efficient\n- Works with the latest browser technologies, including Shadow DOM\n- Seamless\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_START --\u003e\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_END --\u003e\n\n\u003c!-- SHADOW_SECTION_TOC_START --\u003e\n\n## Table of Contents\n\n- [Description](#description)\n  - [Features](#features)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n  - [NPM](#npm)\n  - [Yarn](#yarn)\n- [Applying the polyfill](#applying-the-polyfill)\n- [Usage](#usage)\n  - [Declarative API](#declarative-api)\n  - [Imperative API](#imperative-api)\n- [Dependencies \u0026 Browser support](#dependencies--browser-support)\n- [Contributing](#contributing)\n- [Maintainers](#maintainers)\n- [Backers](#backers)\n  - [Patreon](#patreon)\n- [FAQ](#faq)\n  - [Are there any known quirks?](#are-there-any-known-quirks)\n- [License](#license)\n\n\u003c!-- SHADOW_SECTION_TOC_END --\u003e\n\n\u003c!-- SHADOW_SECTION_INSTALL_START --\u003e\n\n## Install\n\n### NPM\n\n```\n$ npm install scroll-behavior-polyfill\n```\n\n### Yarn\n\n```\n$ yarn add scroll-behavior-polyfill\n```\n\n\u003c!-- SHADOW_SECTION_INSTALL_END --\u003e\n\n## Applying the polyfill\n\nThe polyfill will be feature detected and applied if and only if the browser doesn't support the property already.\nTo include it, add this somewhere:\n\n```typescript\nimport \"scroll-behavior-polyfill\";\n```\n\nHowever, it is strongly suggested that you only include the polyfill for browsers that doesn't already support `scroll-behavior`.\nOne way to do so is with an async import:\n\n```typescript\nif (!(\"scrollBehavior\" in document.documentElement.style)) {\n\tawait import(\"scroll-behavior-polyfill\");\n}\n```\n\nAlternatively, you can use [Polyfill.app](https://github.com/wessberg/Polyfiller) which uses this polyfill and takes care of only loading the polyfill if needed as well as adding the language features that the polyfill depends on (See [dependencies](#dependencies--browser-support)).\n\n\u003c!-- SHADOW_SECTION_USAGE_START --\u003e\n\n## Usage\n\n\u003c!-- SHADOW_SECTION_USAGE_END --\u003e\n\n### Declarative API\n\nYou can define the `scroll-behavior` of Elements via one of the following approaches:\n\n- A style attribute including a `scroll-behavior` property.\n- An element with a `scroll-behavior` attribute.\n- Or, an element with a `CSSStyleDeclaration` with a `scrollBehavior` property.\n\nThis means that either of the following approaches will work:\n\n```html\n\u003c!-- Works just fine when given in the 'style' attribute --\u003e\n\u003cdiv style=\"scroll-behavior: smooth\"\u003e\u003c/div\u003e\n\u003c!-- Works just fine when given as an attribute of the name 'scroll-behavior' --\u003e\n\u003cdiv scroll-behavior=\"smooth\"\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n\t// Works jut fine when given as a style property\n\telement.style.scrollBehavior = \"smooth\";\n\u003c/script\u003e\n```\n\nSee [this section](#are-there-any-known-quirks) for information about why `scroll-behavior` values provided in stylesheets won't be discovered by the polyfill.\n\n### Imperative API\n\nYou can of course also use the imperative `scroll()`, `scrollTo`, `scrollBy`, and `scrollIntoView` APIs and provide `scroll-behavior` options.\n\nFor example:\n\n```typescript\n// Works for the window object\nwindow.scroll({\n\tbehavior: \"smooth\",\n\ttop: 100,\n\tleft: 0\n});\n\n// Works for any element (and supports all options)\nmyElement.scrollIntoView();\n\nmyElement.scrollBy({\n\tbehavior: \"smooth\",\n\ttop: 50,\n\tleft: 0\n});\n```\n\nYou can also use the `scrollTop` and `scrollLeft` setters, both of which works with the polyfill too:\n\n```typescript\nelement.scrollTop += 100;\nelement.scrollLeft += 50;\n```\n\n## Dependencies \u0026 Browser support\n\nThis polyfill is distributed in ES3-compatible syntax, but is using some modern APIs and language features which must be available:\n\n- `requestAnimationFrame`\n- `Object.getOwnPropertyDescriptor`\n- `Object.defineProperty`\n\nFor by far the most browsers, these features will already be natively available.\nGenerally, I would highly recommend using something like [Polyfill.app](https://github.com/wessberg/Polyfiller) which takes care of this stuff automatically.\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_START --\u003e\n\n## Contributing\n\nDo you want to contribute? Awesome! Please follow [these recommendations](./CONTRIBUTING.md).\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_END --\u003e\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_START --\u003e\n\n## Maintainers\n\n| \u003cimg alt=\"Frederik Wessberg\" src=\"https://avatars2.githubusercontent.com/u/20454213?s=460\u0026v=4\" height=\"70\"   /\u003e                                             |\n| ----------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Frederik Wessberg](mailto:frederikwessberg@hotmail.com)\u003cbr\u003e\u003cstrong\u003eTwitter\u003c/strong\u003e: [@FredWessberg](https://twitter.com/FredWessberg)\u003cbr\u003e_Lead Developer_ |\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_START --\u003e\n\n## Backers\n\n### Patreon\n\n[Become a backer](https://www.patreon.com/bePatron?u=11315442) and get your name, avatar, and Twitter handle listed here.\n\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Backers on Patreon\" src=\"https://patreon-badge.herokuapp.com/11315442.png\"  width=\"500\"  /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_FAQ_START --\u003e\n\n## FAQ\n\n\u003c!-- SHADOW_SECTION_FAQ_END --\u003e\n\n### Are there any known quirks?\n\n- `scroll-behavior` properties declared only in stylesheets won't be discovered. This is because [polyfilling CSS is hard and really bad for performance](https://philipwalton.com/articles/the-dark-side-of-polyfilling-css/).\n\n\u003c!-- SHADOW_SECTION_LICENSE_START --\u003e\n\n## License\n\nMIT © [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))\n\n\u003c!-- SHADOW_SECTION_LICENSE_END --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2Fscroll-behavior-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwessberg%2Fscroll-behavior-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2Fscroll-behavior-polyfill/lists"}