国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

基于Vue實現(xiàn)頁面切換左右滑動效果

2024-05-06 15:13:17
字體:
供稿:網(wǎng)友

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

HTML文本頁面:

<template> <div id="app>  <transition :name="direction" mode="out-in"> <!--動態(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']  // 將需要切換效果的路由名稱組成一個數(shù)組  const toName = to.name  // 即將進入的路由名字  const fromName = from.name  // 即將離開的路由名字  const toIndex = list.indexOf(toName)  // 進入下標  const fromIndex = list.indexOf(fromName)  // 離開下標  let direction = ''  if (toIndex > -1 && fromIndex > -1) {  // 如果下標都存在   if (toIndex < fromIndex) {     // 如果進入的下標小于離開的下標,那么是左滑    direction = 'left'   } else {    direction = 'right'     // 如果進入的下標大于離開的下標,那么是右滑   }  }  store.state.viewDirection = direction //這里使用vuex進行賦值  return next() })

在App.vue文件中,進行計算屬性:

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進行動畫效果定義:使用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) }}            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 林甸县| 广安市| 钦州市| 翁牛特旗| 平武县| 齐河县| 贡觉县| 德惠市| 融水| 商都县| 明星| 瑞丽市| 广德县| 临桂县| 陇西县| 广元市| 云霄县| 逊克县| 金秀| 洪江市| 连江县| 台中县| 阳东县| 丰城市| 安国市| 克拉玛依市| 潼南县| 图片| 洛扎县| 安仁县| 桂东县| 贵港市| 商丘市| 阿克| 安图县| 巴林右旗| 滦平县| 尖扎县| 广汉市| 双牌县| 伊宁市|