Giter Site home page Giter Site logo

pageslippage's Introduction

README

Vue-router简单实现页面左右过渡Demo

  • 在路由的原型上加一个goback函数,判断路由是不是返回上一页

      Router.prototype.goback = function () {
        this.isback = true
        window.history.go(-1)
      }
    

返回上一页应该调用 this.$router.goback()

  • 需要实现路由过渡效果必须在显示区加上transition标签,绑定一个变量

       <template>
         <transition :name='transitionName'>
            <router-view class="content"/>
         </transition>
       </template>
    
  • watch观察路由,判断路由是前进还是后退 ,从而控制Class改变过渡效果

       export default {
          data() {
            return {
              transitionName: 'fade-left'
            }
          },
          watch: {
            '$route' (to, from) {
              let isBack = this.$router.isback
              if (isBack) {
                this.transitionName = 'fade-right'
              } else {
                this.transitionName = 'fade-left'
              }
              this.$router.isback = false
            }
          }
        }
    
  • CSS样式

        .fade-left-enter, .fade-right-leave-active {
          -webkit-transform: translate(100%, 0);
          transform: translate(100%, 0);
          z-index: 999;
        }
        .fade-left-leave-active, .fade-right-enter {
          -webkit-transform: translate(-100px, 0);
          transform: translate(-100px, 0);
          transition-delay: .1s;
        }
    

pageslippage's People

Contributors

zhanzhanhu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.