{"id":13426711,"url":"https://github.com/flesler/jquery.scrollTo","last_synced_at":"2025-03-15T21:31:45.993Z","repository":{"id":3556047,"uuid":"4617120","full_name":"flesler/jquery.scrollTo","owner":"flesler","description":"Lightweight, cross-browser and highly customizable animated scrolling with jQuery","archived":false,"fork":false,"pushed_at":"2021-03-15T16:13:37.000Z","size":139,"stargazers_count":3684,"open_issues_count":0,"forks_count":1024,"subscribers_count":154,"default_branch":"master","last_synced_at":"2025-03-11T20:14:06.609Z","etag":null,"topics":["anchors","animated","animation","browser","demo","flesler","jquery","links","scroll","scrollto"],"latest_commit_sha":null,"homepage":"http://demos.flesler.com/jquery/scrollTo/","language":"JavaScript","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/flesler.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}},"created_at":"2012-06-10T18:04:58.000Z","updated_at":"2025-03-08T04:34:35.000Z","dependencies_parsed_at":"2022-07-10T16:02:59.462Z","dependency_job_id":null,"html_url":"https://github.com/flesler/jquery.scrollTo","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/flesler%2Fjquery.scrollTo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flesler%2Fjquery.scrollTo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flesler%2Fjquery.scrollTo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flesler%2Fjquery.scrollTo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flesler","download_url":"https://codeload.github.com/flesler/jquery.scrollTo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475364,"owners_count":20296711,"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":["anchors","animated","animation","browser","demo","flesler","jquery","links","scroll","scrollto"],"created_at":"2024-07-31T00:01:42.301Z","updated_at":"2025-03-15T21:31:45.626Z","avatar_url":"https://github.com/flesler.png","language":"JavaScript","readme":"# jQuery.scrollTo\n\nLightweight, cross-browser and highly customizable animated scrolling with jQuery\n\n[![](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/2081384/fleslerjquery-scrollTo-on-GitHub)\n[![GitHub version](https://badge.fury.io/gh/flesler%2Fjquery.scrollTo.svg)](http://badge.fury.io/gh/flesler%2Fjquery.scrollTo)\n\n## Installation\nThe plugin requires jQuery 1.8 or higher.\n\nVia [bower](https://github.com/flesler/jquery.scrollTo/blob/master/bower.json):\n```bash\nbower install jquery.scrollTo\n```\nVia [npm](https://www.npmjs.com/package/jquery.scrollto):\n```bash\nnpm install jquery.scrollto\n```\nVia [packagist](https://packagist.org/packages/flesler/jquery.scrollTo):\n```php\nphp composer.phar require --prefer-dist flesler/jquery.scrollto \"*\"\n```\n\n### Using a public CDN\n\nCDN provided by [jsdelivr](http://www.jsdelivr.com/#!jquery.scrollto)\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.3/jquery.scrollTo.min.js\"\u003e\u003c/script\u003e\n```\nCDN provided by [cdnjs](https://cdnjs.com/libraries/jquery-scrollTo)\n```html\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery-scrollTo/2.1.3/jquery.scrollTo.min.js\"\u003e\u003c/script\u003e\n```\n\n### Downloading Manually\n\nIf you want the latest stable version, get the latest release from the [releases page](https://github.com/flesler/jquery.scrollTo/releases).\n\n## 2.0\n\nVersion 2.0 has been recently released. It is mostly backwards compatible, if you have any issue first check [this link](https://github.com/flesler/jquery.scrollTo/wiki/Migrating-to-2.0).\nIf your problem is not solved then go ahead and [report the issue](https://github.com/flesler/jquery.scrollTo/issues/new).\n\n## Usage\n\njQuery.scrollTo's signature is designed to resemble [$().animate()](http://api.jquery.com/animate/).\n\n```js\n$(element).scrollTo(target[,duration][,settings]);\n```\n\n### _element_\n\nThis must be a scrollable element, to scroll the whole window use `$(window)`.\n\n### _target_\n\nThis defines the position to where `element` must be scrolled. The plugin supports all these formats:\n * A number with a fixed position: `250`\n * A string with a fixed position with px: `\"250px\"`\n * A string with a percentage (of container's size): `\"50%\"`\n * A string with a relative step: `\"+=50px\"`\n * An object with `left` and `top` containining any of the aforementioned: `{left:250, top:\"50px\"}`\n * The string `\"max\"` to scroll to the end.\n * A string selector that will be relative to the element to scroll: `\".section:eq(2)\"`\n * A DOM element, probably a child of the element to scroll: `document.getElementById(\"top\")`\n * A jQuery object with a DOM element: `$(\"#top\")`\n\n### _settings_\n\nThe `duration` parameter is a shortcut to the setting with the same name.\nThese are the supported settings:\n * __axis__: The axes to animate: `xy` (default), `x`, `y`, `yx`\n * __interrupt__: If `true` will cancel the animation if the user scrolls. Default is `false`\n * __limit__: If `true` the plugin will not scroll beyond the container's size. Default is `true`\n * __margin__: If `true`, subtracts the margin and border of the `target` element. Default is `false`\n * __offset__: Added to the final position, can be a number or an object with `left` and `top`\n * __over__: Adds a % of the `target` dimensions: `{left:0.5, top:0.5}`\n * __queue__: If `true` will scroll one `axis` and then the other. Default is `false`\n * __onAfter(target, settings)__: A callback triggered when the animation ends (jQuery's `complete()`)\n * __onAfterFirst(target, settings)__: A callback triggered after the first axis scrolls when queueing\n\nYou can add any setting supported by [$().animate()](http://api.jquery.com/animate/#animate-properties-options) as well:\n\n * __duration__: Duration of the animation, default is `0` which makes it instantaneous\n * __easing__: Name of an easing equation, you must register the easing function: `swing`\n * __fail()__: A callback triggered when the animation is stopped (f.e via `interrupt`)\n * __step()__: A callback triggered for every animated property on every frame\n * __progress()__: A callback triggered on every frame\n * And more, check jQuery's [documentation](http://api.jquery.com/animate/#animate-properties-options)\n\n### window shorthand\n\nYou can use `$.scrollTo(...)` as a shorthand for `$(window).scrollTo(...)`.\n\n### Changing the default settings\n\nAs with most plugins, the default settings are exposed so they can be changed.\n```js\n$.extend($.scrollTo.defaults, {\n  axis: 'y',\n  duration: 800\n});\n```\n\n### Stopping the animation\n\njQuery.scrollTo ends up creating ordinary animations which can be stopped by calling [$().stop()](http://api.jquery.com/stop/) or [$().finish()](http://api.jquery.com/finish/) on the same element you called `$().scrollTo()`, including the `window`.\nRemember you can pass a `fail()` callback to be called when the animation is stopped.\n\n### onAfter and requestAnimationFrame\n\njQuery.scrollTo has a `onAfter` callback for work that runs after the animation finishes. It will be called before the `scroll` event fires. To combat this you can use  [requestAnimationFrame](http://caniuse.com/#feat=requestanimationframe) to do work on the next tick. It is available in many browsers, but you may want to [polyfill](https://github.com/chrisdickinson/raf) for the few it does not support.\n```js\n$.scrollTo(100, {\n  onAfter: function() {\n    requestAnimationFrame(function() {\n        $(\".result\").addClass(\"selected\");\n    });\n  }\n});\n```\n\n## Demo\n\nCheck the [demo](http://demos.flesler.com/jquery/scrollTo/) to see every option in action.\n\n## Complementary plugins\n\nThere are two plugins, also created by me that depend on jQuery.scrollTo and aim to simplify certain use cases.\n\n### [jQuery.localScroll](https://github.com/flesler/jquery.localScroll)\n\nThis plugin makes it very easy to implement anchor navigation.\nIf you don't want to include another plugin, you can try using something like [this minimalistic gist](https://gist.github.com/flesler/3f3e1166690108abf747).\n\n### [jQuery.serialScroll](https://github.com/flesler/jquery.serialScroll)\n\nThis plugin simplifies the creation of scrolling slideshows.\n\n## Troubleshooting\n\n- `Cannot read property 'propHooks' of undefined`: You are most likely using the slim version jQuery, which doesn't include the effects module. The plugin cannot function without it and you'll need the full version.\n\n- **The element doesn't scroll**: A good approach to debug is to set `overflow: auto` temporarily to the scrollable element, to make sure it would be manually scrollable. If you don't see any scrollbar, the problem is likely in the HTML/CSS.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2007 Ariel Flesler \u003caflesler@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["JavaScript","13. 页面交互","Web 前端"],"sub_categories":["13.11 平滑滚动插件(Smooth Scroll) ###","13.11 平滑滚动插件(Smooth Scroll)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflesler%2Fjquery.scrollTo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflesler%2Fjquery.scrollTo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflesler%2Fjquery.scrollTo/lists"}