{"id":16439295,"url":"https://github.com/jeneser/vue-scroll-behavior","last_synced_at":"2026-03-15T04:12:30.986Z","repository":{"id":118362342,"uuid":"93174955","full_name":"jeneser/vue-scroll-behavior","owner":"jeneser","description":"Customize the scrolling position on route navigation. Especially hash mode.","archived":false,"fork":false,"pushed_at":"2020-08-01T14:52:17.000Z","size":1030,"stargazers_count":141,"open_issues_count":7,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T16:19:36.303Z","etag":null,"topics":["scroll-behavior","vue","vue-cli","vue-router","vue2"],"latest_commit_sha":null,"homepage":"https://jeneser.github.io/vue-scroll-behavior","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/jeneser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-06-02T14:41:02.000Z","updated_at":"2024-05-04T17:49:02.000Z","dependencies_parsed_at":"2024-01-08T08:56:37.259Z","dependency_job_id":null,"html_url":"https://github.com/jeneser/vue-scroll-behavior","commit_stats":{"total_commits":44,"total_committers":5,"mean_commits":8.8,"dds":0.2727272727272727,"last_synced_commit":"bcf8abd2356e0d4dcb73de11855b4244308195ec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeneser%2Fvue-scroll-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeneser%2Fvue-scroll-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeneser%2Fvue-scroll-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeneser%2Fvue-scroll-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeneser","download_url":"https://codeload.github.com/jeneser/vue-scroll-behavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065281,"owners_count":21041872,"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-behavior","vue","vue-cli","vue-router","vue2"],"created_at":"2024-10-11T09:08:49.021Z","updated_at":"2026-03-15T04:12:25.941Z","avatar_url":"https://github.com/jeneser.png","language":"JavaScript","funding_links":[],"categories":["UI实用程序","Components \u0026 Libraries","UI Utilities [🔝](#readme)","UI Utilities"],"sub_categories":["滚动","UI Utilities","Scroll"],"readme":"## vue-scroll-behavior\n\n**Customize the scrolling position on route navigation**\n\n[![npm version](https://badge.fury.io/js/vue-scroll-behavior.svg)](https://badge.fury.io/js/vue-scroll-behavior) [![Build Status](https://travis-ci.org/jeneser/vue-scroll-behavior.svg?branch=master)](https://travis-ci.org/jeneser/vue-scroll-behavior) [![David](https://img.shields.io/david/expressjs/express.svg?style=flat-square)](https://github.com/jeneser/douban) [![Percentage of issues still open](http://isitmaintained.com/badge/open/jeneser/vue-scroll-behavior.svg)](http://isitmaintained.com/project/jeneser/vue-scroll-behavior \"Percentage of issues still open\") [![PR](https://img.shields.io/badge/PR-welcome-brightgreen.svg)](https://github.com/jeneser/vue-scroll-behavior/pulls) [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/jeneser/vue-scroll-behavior/blob/master/LICENSE)\n\n| [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/edge.png\" alt=\"IE / Edge\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eIE / Edge | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/firefox.png\" alt=\"Firefox\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eFirefox | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/chrome.png\" alt=\"Chrome\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eChrome | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/safari.png\" alt=\"Safari\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eSafari | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/opera.png\" alt=\"Opera\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eOpera | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/safari-ios.png\" alt=\"iOS Safari\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eiOS | [\u003cimg src=\"https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/chrome-android.png\" alt=\"Chrome for Android\" width=\"16px\" height=\"16px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eAndroid |\n|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|\n| IE9+, Edge| \u0026check;| \u0026check; | \u0026check; | \u0026check; | \u0026check; | \u0026check;\n\n\n## Table of content\n\n- [Demo](#demo)\n- [Installation](#installation)\n- [Description](#description)\n- [Example](#example)\n- [Options](#options)\n- [ChangeLog](#ChangeLog)\n- [Contribute](#Contribute)\n\n## Demo\nYou can check vue-scroll-behavior demos at:\n\nDouban: **https://jeneser.github.io/douban**\n\nSimple: **https://jeneser.github.io/vue-scroll-behavior**\n\n## Installation\n\n#### NPM\n```bash\nnpm install vue-scroll-behavior --save\n```\n\n```javascript\nimport vueScrollBehavior from 'vue-scroll-behavior'\n\nVue.use(vueScrollBehavior, { router: router })\n```\n\n#### Direct include\n\nIf you are using Vue globally, just include `vue-scroll-behavior.js` and it will automatically install it. Then, you need call `Vue.$vueScrollBehavior(router)` pass the router instance `router`.\n\n```html\n\u003cscript src=\"path/to/vue-scroll-behavior.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  Vue.$vueScrollBehavior(router)\n\u003c/script\u003e\n```\n\n**CDN**\n\n```html\n\u003cscript src=\"https://unpkg.com/vue-scroll-behavior@0.2.0/dist/vue-scroll-behavior.js\"\u003e\u003c/script\u003e\n```\n\n## Description\n\nWhen using client-side routing, we may want to scroll to top when navigating to a new route, or preserve the scrolling position of history entries just like real page reload does. vue-router allows you to achieve these and even better. But, vue-router scroll behavior feature only works in HTML5 history mode...\n\n**`vue-scroll-behavior` allows you to customize the scrolling position on route navigation. Especially hash mode. You just need to tell it which routes need to be processed, and it will do that automatically**\n\n**By default, It will scroll to the saved position. If you ignore some routes, they will directly scroll to the top**\n\n**Of course, If you have some special scenes, we also provide some options, and you can manually use them to save or restore the scroll position**\n\n**If you use transitions on all of your route changes, use the _delay_ option to delay the scroll until the appropriate point (e.g. the middle of the changeover).**\n## Features\n\n* **Simplicity** - only need to call `Vue.vueScrollBehavior(router)`\n* **Compatibility** - Working in HTML5 history mode and hash mode\n* **Automatically** - Automatically saves or restores the scroll position\n* **Customizable** - Can manually save or restore the scroll position\n\n## Example\n\nWhen used with a module system, you can install it via `Vue.use()`, then pass some opts:\n\n```javascript\nimport Vue from 'vue'\nimport router from './router'\nimport vueScrollBehavior from 'vue-scroll-behavior'\n\n// Using vueScrollBehavior\nVue.use(vueScrollBehavior, {\n  router: router,    // The router instance\n  el: '#app',        // Custom element\n  maxLength: 100,    // Saved history List max length\n  ignore: [/\\/boo/, /\\/zoo/],    // ignore some routes, they will directly scroll to the top\n  delay: 0          // Delay by a number of milliseconds\n})\n```\n\nFor additional examples and detailed description check the demo. **https://jeneser.github.io/douban**\n\nYou can clone this repository. Check the silmp demo.\n\n```bash\n# install dependencies\nnpm install\n\n# serve with hot reload at localhost:8080\nnpm run dev\n```\n\n## Options\n\nList of available Options:\n\nProp           | Data Type  | Default   | Description\n-------------- | ---------- | --------- | -----------\n`router`       | Object     |           | The router instance: `const router = new VueRouter({})`\n`el`           | String     | null      | CSS selector: `#app`\n`ignore`       | Array      | `[ ]`     | **RegExp** list to ignore some routes, they will directly scroll to the top\n`maxLength`    | Number     | `50`      | Saved history List max length\n`delay`        | Number     | `0`       | Delay scroll by a number of milliseconds\n\n\n## ChangeLog\n\nThis project uses semantic versioning. [Learn more](http://semver.org/)\n\n- October 27, 2017:\n  - Publish @0.2.0 Merged PR[#9](https://github.com/jeneser/vue-scroll-behavior/pull/9), Add delay\n- June 24, 2017:\n  - Publish @0.1.6 Fix issue[#2](https://github.com/jeneser/vue-scroll-behavior/issues/2)\n- June 7, 2017:\n  - Publish @0.1.5 Add some opts\n- June 5, 2017:\n  - Publish @0.1.3\n  - Publish @0.1.4\n- June 4, 2017:\n  - Fix some bug, Perform browser testing\n  - Publish @0.1.2\n\n## Contribute\n\nPlease make sure to read the [Contributing Guide](https://github.com/jeneser/vue-scroll-behavior/blob/master/CONTRIBUTING.md) before making a pull request.\n\n```bash\n# install dependencies\nnpm install\n\n# serve with hot reload at localhost:8080\nnpm run dev\n\n# build library and demo for production\nnpm run build\n```\n\n## License\n\n[MIT](https://github.com/jeneser/douban/blob/master/LICENSE) Copyright (c) 2017 Jeneser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeneser%2Fvue-scroll-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeneser%2Fvue-scroll-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeneser%2Fvue-scroll-behavior/lists"}