滑动tab及3d翻页组件

滑动Tab组件(swipe-tab)

基本思路

1.监听如下touch事件

touchstart: //手指放到屏幕上时触发vue

touchmove: //手指在屏幕上滑动时触发git

touchend: //手指离开屏幕时触发github

2.计算滑动值并设置

在touchmove事件回调中动态设置容器的transform中的translate3d属性,以达到tab随滑动而移动的效果bash

3.在touchend回调中设置滑动切换tab的阈值

即在tab滑动超出必定阈值时释放,tab自动切换dom

在线浏览

推荐手机访问ui

源码

详见个人githubspa

翻页组件(touch-flipbook

dom结构

<div class="touch-flipbook" ref="touchCon" @touchstart.prevent="TouchStart" @touchmove.prevent="TouchMove"
@touchend="TouchEnd">
    <div class="page p0">
    <!-- /* page有先后两面 */ -->
        <div class="front">0正</div>
        <div class="back">0反</div>
    </div>
    <!-- /* page2为翻页以后显示的*/  -->
    <div class="page p1">
        <div class="front">1正</div>
        <div class="back">1反</div>
    </div>
    <div class="page p2">
        <div class="front">2正</div>
        <div class="back">2反</div>
    </div>
</div>
复制代码

touch事件的处理与上述滑动Tab的处理方式大体相同,不一样在于3d

此处需动态设置为transform中的rotate属性。code

须要注意的有如下几点:orm

  • 因为front跟back是重叠的,经过翻转以后back也会出现镜像,此时需设置 scaleY(1)来解决镜像问题。
  • z-index须要特别关注,越上面的page的z-index越大,翻页前front的z-index大于back,翻页后相反
  • 每个page的翻转值需保存起来,方便后续翻页翻回该页的时候修改。

在线浏览

推荐手机访问

源码

详见个人github

相关文章
相关标签/搜索