线上演示地址1 http://dlvr.netpi.me/all
线上演示地址2(https) https://dlvr.now.sh
vue
vuex
bulma
作为UI框架
Swiper 来做图片滑动轮播
animate.css
来实现动画效果 (弹性滑动 / 淡入淡出)
vue-router
实现浏览器 history 模式
利用 Swiper 实现
-
利用vue-router 实现history模式
-
利用正则表达式判断页面深度
if(pathdeep<=1) return =>目录导航
else => 导航部分替换成 回退导航
// 判断页面深度部分 pathDeep(){ const patharr = this.$route.path.match(/(\/[^/]+)/g)||[] return patharr.length }
zepto
+ vue-router
实现页面滑动轮播, 具体实现如下
- 利用
vue-router
获取到path
zepto
监听滑动事件- 判断下次跳转目标 利用
router.replace(location)
实现更换地址
部分代码
$("#wrap").on('swipeRight',function(){
nextTo(path,'right')
})
$("#wrap").on('swipeLeft',function(){
nextTo(path,'left')
})
function nextTo(pathname,direction="left") {
const arr = ["/all","/cartoon","/game","/movie","/try","/scenery"]
let index = arr.findIndex(item => item == pathname)
let nextIndex = 0
console.log('pathname',pathname)
if(direction === 'left'){
nextIndex = index == arr.length-1
? 0
: index+1
}
if(direction === 'right'){
nextIndex = index === 0
? arr.length-1
: index-1
}
router.replace(arr[nextIndex])
}