首页 > 解决方案 > hammer.js 向右滑动下一页

问题描述

我想向右滑动下一页并向右滑动上一页,我搜索了很长时间的方法,似乎没有任何工作

hammer.js 似乎是最有前途的

hammertime.get('swipe').set({ direction: Hammer. });

下面建议的脚本似乎不起作用,还有其他建议吗?

标签: javascripthammer.js

解决方案


const hammerTime = new Hammer(someElement)
hammerTime.on('swipeleft swiperight', (event) => {
  switch(event.type) {
    case 'swipeleft': 
      window.location.href = "https://someurl.com"
      break
    case 'swiperight':
      window.location.href = "https://someotherurl.com"
      break
  }
})

或者

hammerTime.on('swipeleft', (event) => {
  window.location.href = "https://someurl.com"
})
hammerTime.on('swiperight', (event) => {
  window.location.href = "https://someotherurl.com"
})

推荐阅读