前言
在awesomes上尋找移動(dòng)端框架的時(shí)候意外發(fā)現(xiàn)了vux的頁面切換效果,后面由于其他考慮沒有選用vuex但是這個(gè)切換效果確實(shí)感覺很有新意,也就看了下源碼,這里貼一份備用。
需要用到的技術(shù)棧:Vue+Vuex
先看看效果圖

過渡動(dòng)畫
示例代碼
//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.jsconst 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里面主要思想就是給路由增加一個(gè)索引存到sessionStorage里面,以點(diǎn)擊過的索引值不變,新增加的路由,索引增加1,同時(shí)count+1,這樣在頁面切換時(shí)通過比較索引值的大小,大的向右小的向左,做到左右有規(guī)律的過渡。
好了至此一個(gè)左右切換的過渡效果就成了,最近由于一直在開發(fā)也沒怎么更新文章,如果有朋友有好的想法歡迎與我交流。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對武林網(wǎng)的支持。
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注