HTML文本页面:
if (toIndex > -1 && fromIndex > -1) { // 如果下标都存在
if (toIndex < fromIndex) { // 如果进入的下标小于离开的下标,那么是左滑
direction = 'left'
} else {
direction = 'right' // 如果进入的下标大于离开的下标,那么是右滑
}
}
store.state.viewDirection = direction //这里使用vuex进行赋值
return next()
})
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
待定义引入样式文件:
<div class="jb51code">
<pre class="brush:css;">
// 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);
transform: translate3d(-100%,0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0,0);
transform: translate3d(0,0);
}
}
@keyframes slideInLeft {
from {
-webkit-transform: translate3d(-100%,0);
}
}
.slideInLeft {
-webkit-animation-name: slideInLeft;
animation-name: slideInLeft;
}
@-webkit-keyframes slideInRight {
from {
-webkit-transform: translate3d(100%,0);
transform: translate3d(100%,0);
}
}
@keyframes slideInRight {
from {
-webkit-transform: translate3d(100%,0);
}
}
.slideInRight {
-webkit-animation-name: slideInRight;
animation-name: slideInRight;
}
@-webkit-keyframes slideOutLeft {
from {
-webkit-transform: translate3d(0,0);
}
to {
visibility: hidden;
-webkit-transform: translate3d(-100%,0);
}
}
@keyframes slideOutLeft {
from {
-webkit-transform: translate3d(0,0);
}
}
.slideOutLeft {
-webkit-animation-name: slideOutLeft;
animation-name: slideOutLeft;
}
@-webkit-keyframes slideOutRight {
from {
-webkit-transform: translate3d(0,0);
}
to {
visibility: hidden;
-webkit-transform: translate3d(100%,0);
}
}
@keyframes slideOutRight {
from {
-webkit-transform: translate3d(0,0);
}
}
.slideOutRight {
-webkit-animation-name: slideOutRight;
animation-name: slideOutRight;
}
@-webkit-keyframes inRight {
0% {
-webkit-transform: translate3d(100%,0)
}
to {
-webkit-transform: translateZ(0);
transform: translateZ(0)
}
}
@keyframes inRight {
0% {
-webkit-transform: translate3d(100%,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)
}
}
@keyframes outLeft {
0% {
-webkit-transform: translateZ(0);
transform: translateZ(0)
}
to {
-webkit-transform: translate3d(100%,0)
}
}