温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Vue.js怎么实现微信过渡动画左右切换效果

发布时间:2021-04-23 11:37:34 来源:亿速云 阅读:403 作者:小新 栏目:web开发

这篇文章给大家分享的是有关Vue.js怎么实现微信过渡动画左右切换效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

为什么要使用Vue

Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以创建可维护性和可测试性更强的代码库,Vue允许可以将一个网页分割成可复用的组件,每个组件都包含属于自己的HTML、CSS、JavaScript,以用来渲染网页中相应的地方,所以越来越多的前端开发者使用vue。

需要用到的技术栈:Vue+Vuex

先看看效果图

Vue.js怎么实现微信过渡动画左右切换效果
过渡动画

示例代码

//app.vue <transition :name="'vux-pop-' + (direction === 'forward' ? 'in' : 'out')">  <keep-alive>  <router-view class="router-view" ></router-view>  </keep-alive> </transition> <script>  import { mapState } from 'vuex'  import sideFooter from "./components/Footer.vue"  export default {  name: 'app',  data () {  return {  showFooter : false  }  },  components : {  sideFooter  },  computed:{  ...mapState({  direction: state => state.mutations.direction  })  },  } </script> <style scoped>  .vux-pop-out-enter-active,  .vux-pop-out-leave-active,  .vux-pop-in-enter-active,  .vux-pop-in-leave-active {  will-change: transform;  transition: all 250ms;  height: 100%;  top: 0;  position: absolute;  backface-visibility: hidden;  perspective: 1000;  }  .vux-pop-out-enter {  opacity: 0;  transform: translate3d(-100%, 0, 0);  }  .vux-pop-out-leave-active {  opacity: 0;  transform: translate3d(100%, 0, 0);  }  .vux-pop-in-enter {  opacity: 0;  transform: translate3d(100%, 0, 0);  }  .vux-pop-in-leave-active {  opacity: 0;  transform: translate3d(-100%, 0, 0);  } </style>
// main.js const history = window.sessionStorage; history.clear() let historyCount = history.getItem('count') * 1 || 0; history.setItem('/', 0); router.beforeEach(function (to, from, next) {  const toIndex = history.getItem(to.path);  const fromIndex = history.getItem(from.path);  if (toIndex) {  if (!fromIndex || parseInt(toIndex, 10) > parseInt(fromIndex, 10) || (toIndex === '0' && fromIndex === '0')) {  store.commit('UPDATE_DIRECTION', {direction: 'forward'})  } else {  store.commit('UPDATE_DIRECTION', {direction: 'reverse'})  }  } else {  ++historyCount;  history.setItem('count', historyCount);  to.path !== '/' && history.setItem(to.path, historyCount);  store.commit('UPDATE_DIRECTION', {direction: 'forward'})  }  next() });

这里还用到了vuex,但是我stroe写了很多就不提出来了,主要就是通过 UPDATE_DIRECTION方法更新每一次的路由方向是前进还是后退。

man.js里面主要思想就是给路由增加一个索引存到sessionStorage里面,以点击过的索引值不变,新增加的路由,索引增加1,同时count+1,这样在页面切换时通过比较索引值的大小,大的向右小的向左,做到左右有规律的过渡。

好了至此一个左右切换的过渡效果就成了,最近由于一直在开发也没怎么更新文章,如果有朋友有好的想法欢迎与我交流。

感谢各位的阅读!关于“Vue.js怎么实现微信过渡动画左右切换效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue
AI