最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Vue實(shí)現(xiàn)頁(yè)面切換左右滑動(dòng)效果

 更新時(shí)間:2021年09月09日 14:46:59   作者:嘉爺  
這篇文章主要為大家詳細(xì)介紹了基于Vue實(shí)現(xiàn)頁(yè)面切換左右滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

基于Vue的頁(yè)面切換左右滑動(dòng)效果,具體內(nèi)容如下

HTML文本頁(yè)面:

<template>
 <div id="app>
 <transition :name="direction" mode="out-in"> <!--動(dòng)態(tài)獲得transition 的name值-->
  <router-view class="app-view" wechat-title></router-view>
 </transition>
 </div>
</template>

JS定義代碼:定義在全局js文件里面

router.beforeEach((to, from, next) => {
 const list = ['home', 'group', 'user'] // 將需要切換效果的路由名稱組成一個(gè)數(shù)組
 const toName = to.name // 即將進(jìn)入的路由名字
 const fromName = from.name // 即將離開(kāi)的路由名字
 const toIndex = list.indexOf(toName) // 進(jìn)入下標(biāo)
 const fromIndex = list.indexOf(fromName) // 離開(kāi)下標(biāo)
 let direction = ''

 if (toIndex > -1 && fromIndex > -1) { // 如果下標(biāo)都存在
  if (toIndex < fromIndex) {   // 如果進(jìn)入的下標(biāo)小于離開(kāi)的下標(biāo),那么是左滑
  direction = 'left'
  } else {
  direction = 'right'   // 如果進(jìn)入的下標(biāo)大于離開(kāi)的下標(biāo),那么是右滑
  }
 }

 store.state.viewDirection = direction //這里使用vuex進(jìn)行賦值

 return next()
 })

在App.vue文件中,進(jìn)行計(jì)算屬性:

computed: {

  direction () {
  const viewDir = this.$store.state.viewDirection
  let tranName = ''

  if (viewDir === 'left') {
   tranName = 'view-out'
  } else if (viewDir === 'right') {
   tranName = 'view-in'
  } else {
   tranName = 'fade'
  }

  return tranName
  },
 },

css3進(jìn)行動(dòng)畫(huà)效果定義:使用sass

待定義引入樣式文件:

// Variables
$AnimateHook: "animated";
$AnimateDuration: 0.8s;

// Mixins

// Base Style
.#{$AnimateHook} {
 -webkit-animation-duration: $AnimateDuration;
 animation-duration: $AnimateDuration;
 -webkit-animation-fill-mode: both;
 animation-fill-mode: both;

 // Modifier for infinite repetition
 &.infinite {
 -webkit-animation-iteration-count: infinite;
 animation-iteration-count: infinite;
 }

}

// Slide
@-webkit-keyframes slideInLeft {
 from {
 -webkit-transform: translate3d(-100%, 0, 0);
 transform: translate3d(-100%, 0, 0);
 visibility: visible;
 }

 to {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

}

@keyframes slideInLeft {
 from {
 -webkit-transform: translate3d(-100%, 0, 0);
 transform: translate3d(-100%, 0, 0);
 visibility: visible;
 }

 to {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

}

.slideInLeft {
 -webkit-animation-name: slideInLeft;
 animation-name: slideInLeft;
}

@-webkit-keyframes slideInRight {
 from {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0);
 visibility: visible;
 }

 to {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

}

@keyframes slideInRight {
 from {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0);
 visibility: visible;
 }

 to {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

}

.slideInRight {
 -webkit-animation-name: slideInRight;
 animation-name: slideInRight;
}

@-webkit-keyframes slideOutLeft {
 from {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

 to {
 visibility: hidden;
 -webkit-transform: translate3d(-100%, 0, 0);
 transform: translate3d(-100%, 0, 0);
 }

}

@keyframes slideOutLeft {
 from {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

 to {
 visibility: hidden;
 -webkit-transform: translate3d(-100%, 0, 0);
 transform: translate3d(-100%, 0, 0);
 }

}

.slideOutLeft {
 -webkit-animation-name: slideOutLeft;
 animation-name: slideOutLeft;
}

@-webkit-keyframes slideOutRight {
 from {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

 to {
 visibility: hidden;
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0);
 }

}

@keyframes slideOutRight {
 from {
 -webkit-transform: translate3d(0, 0, 0);
 transform: translate3d(0, 0, 0);
 }

 to {
 visibility: hidden;
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0);
 }

}

.slideOutRight {
 -webkit-animation-name: slideOutRight;
 animation-name: slideOutRight;
}

@-webkit-keyframes inRight {
 0% {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0)
 }

 to {
 -webkit-transform: translateZ(0);
 transform: translateZ(0)
 }

}

@keyframes inRight {
 0% {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0)
 }

 to {
 -webkit-transform: translateZ(0);
 transform: translateZ(0)
 }

}

@-webkit-keyframes outLeft {
 0% {
 -webkit-transform: translateZ(0);
 transform: translateZ(0)
 }

 to {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0)
 }

}

@keyframes outLeft {
 0% {
 -webkit-transform: translateZ(0);
 transform: translateZ(0)
 }

 to {
 -webkit-transform: translate3d(100%, 0, 0);
 transform: translate3d(100%, 0, 0)
 }

}

定義進(jìn)入與離開(kāi)的動(dòng)畫(huà)過(guò)渡:

.fade-enter-active,
.fade-leave-active {
 transition: all .2s ease;
}

.fade-enter,
.fade-leave-active {
 opacity: 0;
}

.view-in-enter-active,
.view-out-leave-active {
 position: absolute;
 top: 0;
 width: 100%;
 padding-top: px2rem($titbarHeight);
 -webkit-animation-duration: .3s;
 animation-duration: .3s;
 -webkit-animation-fill-mode: both;
 animation-fill-mode: both;
 -webkit-backface-visibility: hidden;
 backface-visibility: hidden;
}

.view-in-enter-active {
 -webkit-animation-name: inRight;
 animation-name: inRight;
}

.view-out-leave-active {
 -webkit-animation-name: outLeft;
 animation-name: outLeft;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue實(shí)現(xiàn)帶小數(shù)點(diǎn)的星星評(píng)分

    vue實(shí)現(xiàn)帶小數(shù)點(diǎn)的星星評(píng)分

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)帶小數(shù)點(diǎn)的星星評(píng)分,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • vue 2.0封裝model組件的方法

    vue 2.0封裝model組件的方法

    本篇文章主要介紹了vue 2.0封裝model組件的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • Vue實(shí)現(xiàn)多圖添加顯示和刪除

    Vue實(shí)現(xiàn)多圖添加顯示和刪除

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)多圖添加顯示和刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • vue實(shí)現(xiàn)codemirror代碼編輯器中的SQL代碼格式化功能

    vue實(shí)現(xiàn)codemirror代碼編輯器中的SQL代碼格式化功能

    這篇文章主要介紹了vue實(shí)現(xiàn)codemirror代碼編輯器中的SQL代碼格式化功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Vue項(xiàng)目業(yè)務(wù)邏輯模塊介紹

    Vue項(xiàng)目業(yè)務(wù)邏輯模塊介紹

    這篇文章主要介紹了Vue項(xiàng)目業(yè)務(wù)邏輯,不同的項(xiàng)目有不同的功能,不同的功能需要不同的實(shí)現(xiàn),實(shí)現(xiàn)這些核心功能的代碼就叫業(yè)務(wù)邏輯。所以說(shuō)業(yè)務(wù)邏輯是指一個(gè)實(shí)體單元為了向另一個(gè)實(shí)體單元提供服務(wù),應(yīng)該具備的規(guī)則與流程
    2022-11-11
  • vue.js-div滾動(dòng)條隱藏但有滾動(dòng)效果的實(shí)現(xiàn)方法

    vue.js-div滾動(dòng)條隱藏但有滾動(dòng)效果的實(shí)現(xiàn)方法

    下面小編就為大家分享一篇vue.js-div滾動(dòng)條隱藏但有滾動(dòng)效果的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • vue.js 輸入框輸入值自動(dòng)過(guò)濾特殊字符替換中問(wèn)標(biāo)點(diǎn)操作

    vue.js 輸入框輸入值自動(dòng)過(guò)濾特殊字符替換中問(wèn)標(biāo)點(diǎn)操作

    這篇文章主要介紹了vue.js 輸入框輸入值自動(dòng)過(guò)濾特殊字符替換中問(wèn)標(biāo)點(diǎn)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • Vue如何獲取數(shù)據(jù)列表展示

    Vue如何獲取數(shù)據(jù)列表展示

    這篇文章主要為大家詳細(xì)介紹了Vue如何獲取數(shù)據(jù)列表展示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • 實(shí)例教學(xué)如何寫(xiě)vue插件

    實(shí)例教學(xué)如何寫(xiě)vue插件

    本次小編通過(guò)一個(gè)簡(jiǎn)單的實(shí)例來(lái)教給大家如何寫(xiě)一個(gè)vue插件,以及需要注意的地方,如果有需要的讀者跟著學(xué)習(xí)一下吧。
    2017-11-11
  • vue項(xiàng)目實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方法

    vue項(xiàng)目實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方法

    這篇文章主要給大家分享的是vue項(xiàng)目實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方法,vue-router是前端開(kāi)發(fā)中用來(lái)實(shí)現(xiàn)路由頁(yè)面跳轉(zhuǎn)的一個(gè)模塊。下面小編將帶來(lái)如何在已經(jīng)創(chuàng)建好的vue-router項(xiàng)目基礎(chǔ)下實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn),需要的朋友可以參考一下
    2021-11-11

最新評(píng)論

宜昌市| 屯留县| 承德市| 诸城市| 津南区| 安国市| 台安县| 邢台县| 云龙县| 邻水| 城口县| 沂南县| 祁门县| 阿瓦提县| 镇原县| 改则县| 荣昌县| 赤城县| 西林县| 中西区| 曲阜市| 尼勒克县| 尉氏县| 岗巴县| 廊坊市| 贡嘎县| 景德镇市| 宣武区| 明水县| 永城市| 麻栗坡县| 百色市| 盐池县| 松阳县| 汤阴县| 德阳市| 个旧市| 芷江| 开化县| 梨树县| 富锦市|