欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue.js實(shí)現(xiàn)微信過渡動畫左右切換效果

 更新時間:2017年06月13日 09:03:51   作者:Yunfly  
這篇文章主要給大家介紹了利用Vue.js仿微信過渡動畫左右切換效果的相關(guān)資料,需要用到的技術(shù)棧是Vue+Vuex。文中通過示例代碼介紹的非常詳細(xì),對大家具一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。

前言

awesomes上尋找移動端框架的時候意外發(fā)現(xiàn)了vux的頁面切換效果,后面由于其他考慮沒有選用vuex但是這個切換效果確實(shí)感覺很有新意,也就看了下源碼,這里貼一份備用。

需要用到的技術(shù)棧:Vue+Vuex

先看看效果圖


過渡動畫

示例代碼

//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方法更新每一次的路由方向是前進(jìn)還是后退。

man.js里面主要思想就是給路由增加一個索引存到sessionStorage里面,以點(diǎn)擊過的索引值不變,新增加的路由,索引增加1,同時count+1,這樣在頁面切換時通過比較索引值的大小,大的向右小的向左,做到左右有規(guī)律的過渡。

好了至此一個左右切換的過渡效果就成了,最近由于一直在開發(fā)也沒怎么更新文章,如果有朋友有好的想法歡迎與我交流。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論