{"id":13727412,"url":"https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed","last_synced_at":"2025-05-14T20:04:44.698Z","repository":{"id":32002480,"uuid":"131347106","full_name":"scroll-into-view/smooth-scroll-into-view-if-needed","owner":"scroll-into-view","description":"Smoothly scroll elements into view, cross browser!","archived":false,"fork":false,"pushed_at":"2025-04-03T23:13:28.000Z","size":5022,"stargazers_count":217,"open_issues_count":15,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-07T17:01:54.172Z","etag":null,"topics":["scroll-into-view","scroll-into-view-if-needed","smooth-scrolling"],"latest_commit_sha":null,"homepage":"https://scroll-into-view.dev","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/scroll-into-view.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-27T21:36:59.000Z","updated_at":"2025-02-01T07:37:45.000Z","dependencies_parsed_at":"2024-01-11T23:16:53.630Z","dependency_job_id":"350f2921-4aa5-4276-9a00-514eae1734cb","html_url":"https://github.com/scroll-into-view/smooth-scroll-into-view-if-needed","commit_stats":{"total_commits":1006,"total_committers":9,"mean_commits":"111.77777777777777","dds":0.06163021868787277,"last_synced_commit":"d4dc238f6072cde4f096d9f9cd2863c1f137a37b"},"previous_names":["stipsan/smooth-scroll-into-view-if-needed"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-into-view%2Fsmooth-scroll-into-view-if-needed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-into-view%2Fsmooth-scroll-into-view-if-needed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-into-view%2Fsmooth-scroll-into-view-if-needed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scroll-into-view%2Fsmooth-scroll-into-view-if-needed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scroll-into-view","download_url":"https://codeload.github.com/scroll-into-view/smooth-scroll-into-view-if-needed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248950903,"owners_count":21188368,"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":["scroll-into-view","scroll-into-view-if-needed","smooth-scrolling"],"created_at":"2024-08-03T01:03:54.730Z","updated_at":"2025-04-14T19:46:52.292Z","avatar_url":"https://github.com/scroll-into-view.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![CircleCI Status](https://img.shields.io/circleci/project/github/stipsan/smooth-scroll-into-view-if-needed.svg?style=flat-square)](https://circleci.com/gh/stipsan/smooth-scroll-into-view-if-needed)\n[![npm stat](https://img.shields.io/npm/dm/smooth-scroll-into-view-if-needed.svg?style=flat-square)](https://npm-stat.com/charts.html?package=smooth-scroll-into-view-if-needed)\n[![npm version](https://img.shields.io/npm/v/smooth-scroll-into-view-if-needed.svg?style=flat-square)](https://www.npmjs.com/package/smooth-scroll-into-view-if-needed)\n[![gzip size][gzip-badge]][unpkg-dist]\n[![size][size-badge]][unpkg-dist]\n[![module formats: umd, cjs, and es][module-formats-badge]][unpkg-dist]\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)\n![smooth-scroll-into-view-if-needed](https://user-images.githubusercontent.com/81981/39496447-c1153942-4d9e-11e8-92c8-ad5ac0e406ac.png)\n\nThis is an addon to [`scroll-into-view-if-needed`](https://www.npmjs.com/package/scroll-into-view-if-needed) that [ponyfills](https://ponyfill.com) smooth scrolling.\nAnd while `scroll-into-view-if-needed` use the same default options as browsers and the spec does, this library is a bit more opinionated and include bonus features that help you build great UIs.\n\n## [Demo](https://scroll-into-view-if-needed.netlify.com/)\n\n## Install\n\n```bash\nyarn add smooth-scroll-into-view-if-needed\n```\n\nThe UMD build is also available on [unpkg](https://unpkg.com/smooth-scroll-into-view-if-needed/umd/):\n\n```html\n\u003cscript src=\"https://unpkg.com/smooth-scroll-into-view-if-needed/umd/smooth-scroll-into-view-if-needed.min.js\"\u003e\u003c/script\u003e\n```\n\nYou can find the library on `window.scrollIntoView`.\n\n## Usage\n\n```js\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed'\nconst node = document.getElementById('hero')\n\n// `options.behavior` is set to `smooth` by default so you don't have to pass options like in `scroll-into-view-if-needed`\nscrollIntoView(node)\n\n// combine it with any of the other options from 'scroll-into-view-if-needed'\nscrollIntoView(node, {\n  scrollMode: 'if-needed',\n  block: 'nearest',\n  inline: 'nearest',\n})\n\n// a promise is always returned to help reduce boilerplate\nconst sequence = async () =\u003e {\n  const slide = document.getElementById('slide-3')\n  // First smooth scroll to hero\n  await scrollIntoView(node, { behavior: 'smooth' })\n  // Then we scroll to a slide in a slideshow\n  return scrollIntoView(slide, { behavior: 'smooth' })\n}\n```\n\n## Polyfills\n\nThis library rely on `Promise` and `requestAnimationFrame`. This library does not ship with polyfills for these to keep bundlesizes as low as possible.\n\n## API\n\nCheck the full API in [`scroll-into-view-if-needed`](https://github.com/stipsan/scroll-into-view-if-needed#api).\n\n### scrollIntoView(target, [options]) =\u003e Promise\n\n`scroll-into-view-if-needed` does not return anything, while this library will return a Promise that is resolved when all of the scrolling boxes are finished scrolling.\n\n\u003e The ability to cancel animations will be added in a future version.\n\n### options\n\nType: `Object`\n\n#### behavior\n\nType: `'auto' | 'smooth' | Function`\u003cbr\u003e Default: `'smooth'`\n\nThis option deviates from `scroll-into-view-if-needed` in two ways.\n\n- The default value is `smooth` instead of `auto`\n- Using `smooth` adds it to browsers that miss it, and overrides the native smooth scrolling in the browsers that have it to ensure the scrolling is consistent in any browser.\n\nThe options `auto` or `Function` behaves exactly like in `scroll-into-view-if-needed`.\n\n#### duration\n\nType: `number`\u003cbr\u003e Default: `300`\n\n\u003e Introduced in `v1.1.0`\n\nThis setting is not a hard limit.\nThe duration of a scroll differs depending on how many elements is scrolled, and the capabilities of the browser.\nOn mobile the browser might pause or throttle the animation if the user switches to another tab.\nAnd there might be nothing to scroll.\nNo matter the scenario a Promise is returned so you can await on it.\n\n#### ease\n\nType: `Function`\n\n\u003e Introduced in `v1.1.0`\n\nThe default easing is `easeOutQuint` based on these algorithms: https://gist.github.com/gre/1650294#file-easing-js\n\nLinear example:\n\n```typescript\nscrollIntoView(node, {\n  ease: (t) =\u003e t,\n})\n```\n\nAcceleration until halfway, then deceleration:\n\n```typescript\nscrollIntoView(node, {\n  ease: (t) =\u003e\n    t \u003c 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,\n})\n```\n\nSine easing in and out:\n\n```typescript\nscrollIntoView(node, {\n  ease: (t) =\u003e (1 + Math.sin(Math.PI * t - Math.PI / 2)) / 2,\n})\n```\n\n## Credits\n\n- [smoothscroll](https://github.com/iamdustan/smoothscroll) for the reference implementation of smooth scrolling.\n\n## More documentation will be added\n\n[gzip-badge]: http://img.badgesize.io/https://unpkg.com/smooth-scroll-into-view-if-needed/umd/smooth-scroll-into-view-if-needed.min.js?compression=gzip\u0026label=gzip%20size\u0026style=flat-square\n[size-badge]: http://img.badgesize.io/https://unpkg.com/smooth-scroll-into-view-if-needed/umd/smooth-scroll-into-view-if-needed.min.js?label=size\u0026style=flat-square\n[unpkg-dist]: https://unpkg.com/smooth-scroll-into-view-if-needed/umd/\n[module-formats-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20es-green.svg?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscroll-into-view%2Fsmooth-scroll-into-view-if-needed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscroll-into-view%2Fsmooth-scroll-into-view-if-needed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscroll-into-view%2Fsmooth-scroll-into-view-if-needed/lists"}