先上效果圖,第一個是自動播放,第二個是手滑播放,到最后一頁自動跳轉到第一頁,手滑時,第一頁或者最有一頁會有彈簧效果

畢竟是qq截屏,沒那么高保真,有點影響視覺,請忽略
來講講實現思路,首先,監聽三個事件,touchstart,touchmove,touchend
在touchstart時,記住這個點,把它保存起來,然后touchmove時,計算當前點與start點的距離,把這個值賦給swipe,就實現了滾動的效果;touchend時,判斷當前的位移是否已經達到了切換的閾值,然后再進行判斷是否切換;
以上就是基本思路,來談談細節
1.怎么去實現位移,此處使用transform;
2.切換和到始末頁時,怎么去實現動畫與彈簧的效果,此處用到的是transition,在move時,需要將transition置為null,不然不會跟著手指動,end的時候再把transition加上去,具體代碼我就不多謝了,有空可以去看看我的github monkeyCompoents
組件需要的屬性
1.threshold 切換的閾值
2.duration:動畫的時間
3.isLoop:是否支持循環
4.data:數據對象,如下
[
{
url: 'https://www.baidu.com',
img: 'http://img.zcool.cn/community/01903955448a250000019ae9351fcc.jpg@2o.jpg'
},
{
url: 'https://www.163.com',
img: 'http://img.zcool.cn/community/01aa2056e7aba96ac72558850d314b.jpg'
},
{
url: 'https://www.qq.com',
img: 'http://img.zcool.cn/community/01fa00574ea43732f875a4296255ae.jpg'
},
{
url: 'https://www.sina.com.cn',
img: 'http://img2.yiihuu.com/upimg/seonews/2016/07/15/01c4eb5747bebf6ac72525ae7d6e98.jpg'
}
]