All Projects → jeneser → Vue Scroll Behavior

jeneser / Vue Scroll Behavior

Licence: mit
Customize the scrolling position on route navigation. Especially hash mode.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Scroll Behavior

capacitor-vue-ionicv4-app
sample app using capacitor vuejs and ionicv4 components
Stars: ✭ 70 (-46.97%)
Mutual labels:  vue-cli, vue2, vue-router
Vue Cli Multipage Bootstrap
vue-cli-multipage-bootstrap demo with vue2+vue-router+vuex+bootstrap+markdown for learning vue2.0
Stars: ✭ 105 (-20.45%)
Mutual labels:  vue-cli, vue-router, vue2
Code-VueWapDemo
“Vue教程--Wap端项目搭建从0到1”的源码
Stars: ✭ 19 (-85.61%)
Mutual labels:  vue-cli, vue2, vue-router
Vuemmerce
👉 Responsive ecommerce template 🛒 built with Vue.js and Nuxt.js
Stars: ✭ 223 (+68.94%)
Mutual labels:  vue-cli, vue-router, vue2
Vue Mobile Cli
🚀 Vue移动端多页应用脚手架
Stars: ✭ 112 (-15.15%)
Mutual labels:  vue-cli, vue-router, vue2
Vue-CAMP
VueJS
Stars: ✭ 16 (-87.88%)
Mutual labels:  vue-cli, vue2, vue-router
vue2
【🔥Vue.js资讯📚】目前web前端开发非常火爆的框架;定时更新,欢迎 Star 一下。
Stars: ✭ 415 (+214.39%)
Mutual labels:  vue-cli, vue2, vue-router
Vue Objccn
🔥 Use Vue.js to develop a cross-platform full stack application / 用 Vue.js 开发的跨三端应用
Stars: ✭ 1,993 (+1409.85%)
Mutual labels:  vue-cli, vue-router, vue2
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (+276.52%)
Mutual labels:  vue-cli, vue-router, vue2
Vue2
【🔥Vue.js资讯📚】目前web前端开发非常火爆的框架;定时更新,欢迎 Star 一下。
Stars: ✭ 395 (+199.24%)
Mutual labels:  vue-cli, vue-router, vue2
Vue2 Scaffold
The best scaffold for Vue 2.x based on vue-cli#vuejs-templates/webpack
Stars: ✭ 125 (-5.3%)
Mutual labels:  vue-cli, vue-router, vue2
Pretty Vendor
[零食商贩] - 基于vue全家桶 + koa2 + sequelize + mysql 搭建的移动商城应用
Stars: ✭ 57 (-56.82%)
Mutual labels:  vue-cli, vue-router, vue2
Douban
Awesome douban DEMO created with Vue2.x + Vuex + Vue-router + Superagent
Stars: ✭ 2,324 (+1660.61%)
Mutual labels:  vue-cli, vue-router, vue2
Social
基于Vue的社区论坛项目
Stars: ✭ 102 (-22.73%)
Mutual labels:  vue-cli, vue-router, vue2
Vue2 Demo
Vue 基于 Genesis + TS + Vuex 实现的 SSR demo
Stars: ✭ 2,072 (+1469.7%)
Mutual labels:  vue-cli, vue-router, vue2
huobi-PC
火币桌面客户端,基于electorn-vue开发
Stars: ✭ 56 (-57.58%)
Mutual labels:  vue-cli, vue2, vue-router
Gpk admin
✨ GeekPark Content Management System
Stars: ✭ 150 (+13.64%)
Mutual labels:  vue-cli, vue-router, vue2
Vuetify Todo Pwa
✔️ A simple Todo PWA built with Vue CLI 3 + Vuex + Vuetify.
Stars: ✭ 160 (+21.21%)
Mutual labels:  vue-cli, vue-router, vue2
Vue Home
🏠 A simple project(Vue Community SPA) which bases on vue+vue-cli+vue-router+axios+ scss.
Stars: ✭ 256 (+93.94%)
Mutual labels:  vue-cli, vue-router, vue2
Vue Music
基于vue2.0的网易云音乐播放器,api来自于NeteaseCloudMusicApi,v2.0为最新版本
Stars: ✭ 855 (+547.73%)
Mutual labels:  vue-cli, vue-router, vue2

vue-scroll-behavior

Customize the scrolling position on route navigation

npm version Build Status David Percentage of issues still open PR license

IE / EdgeIE / Edge FirefoxFirefox ChromeChrome SafariSafari OperaOpera iOS SafariiOS Chrome for AndroidAndroid
IE9+, Edge

Table of content

Demo

You can check vue-scroll-behavior demos at:

Douban: https://jeneser.github.io/douban

Simple: https://jeneser.github.io/vue-scroll-behavior

Installation

NPM

npm install vue-scroll-behavior --save
import vueScrollBehavior from 'vue-scroll-behavior'

Vue.use(vueScrollBehavior, { router: router })

Direct include

If 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.

<script src="path/to/vue-scroll-behavior.js"></script>

<script>
  Vue.$vueScrollBehavior(router)
</script>

CDN

<script src="https://unpkg.com/[email protected]/dist/vue-scroll-behavior.js"></script>

Description

When 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...

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

By default, It will scroll to the saved position. If you ignore some routes, they will directly scroll to the top

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

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).

Features

  • Simplicity - only need to call Vue.vueScrollBehavior(router)
  • Compatibility - Working in HTML5 history mode and hash mode
  • Automatically - Automatically saves or restores the scroll position
  • Customizable - Can manually save or restore the scroll position

Example

When used with a module system, you can install it via Vue.use(), then pass some opts:

import Vue from 'vue'
import router from './router'
import vueScrollBehavior from 'vue-scroll-behavior'

// Using vueScrollBehavior
Vue.use(vueScrollBehavior, {
  router: router,    // The router instance
  el: '#app',        // Custom element
  maxLength: 100,    // Saved history List max length
  ignore: [/\/boo/, /\/zoo/],    // ignore some routes, they will directly scroll to the top
  delay: 0          // Delay by a number of milliseconds
})

For additional examples and detailed description check the demo. https://jeneser.github.io/douban

You can clone this repository. Check the silmp demo.

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

Options

List of available Options:

Prop Data Type Default Description
router Object The router instance: const router = new VueRouter({})
el String null CSS selector: #app
ignore Array [ ] RegExp list to ignore some routes, they will directly scroll to the top
maxLength Number 50 Saved history List max length
delay Number 0 Delay scroll by a number of milliseconds

ChangeLog

This project uses semantic versioning. Learn more

  • October 27, 2017:
    • Publish @0.2.0 Merged PR#9, Add delay
  • June 24, 2017:
    • Publish @0.1.6 Fix issue#2
  • June 7, 2017:
    • Publish @0.1.5 Add some opts
  • June 5, 2017:
    • Publish @0.1.3
    • Publish @0.1.4
  • June 4, 2017:
    • Fix some bug, Perform browser testing
    • Publish @0.1.2

Contribute

Please make sure to read the Contributing Guide before making a pull request.

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build library and demo for production
npm run build

License

MIT Copyright (c) 2017 Jeneser

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].