Hammerjs没有检测到滑动运动
我使用nuxt使用 Hammerjs 2.0.8 ,我似乎无法使其检测到滑动运动。这是我完成设置的方式。如果我将识别器更改为[Hammer.pan,{Direction:Hammer.direction_horizontal}]
和on Pan Event Hammer.on('Pan',this.handletouchevents);它运行
this.handletouchevents
方法。
<template>
<v-app>
<v-main>
<v-container id="touch-container" fluid>
<div class="items">
...
</div>
</v-container>
</v-main>
</v-app>
</template>
<script>
export default {
mounted () {
const Hammer = require('hammerjs')
const touchContainer = document.getElementById('touch-container')
const hammer = new Hammer.Manager(touchContainer, {
recognizers: [
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }]
]
})
hammer.on('swipe', this.handleTouchEvents)
},
methods: {
handleTouchEvents (e) {
alert(e.type)
}
}
}
</script>
<style scoped>
#touch-container {
height: 100%;
min-width: 100%;
overflow-x: hidden;
}
#items {
touch-action: pan-y;
}
</style>
知道如何解决这个问题吗?
I'm using Hammerjs 2.0.8 with Nuxt, and I can't seem to make it detect swipe motion. Here's how I've done the setup. If I change the recognizer to [Hammer.Pan, { direction: Hammer.DIRECTION_HORIZONTAL }]
and on pan event hammer.on('pan', this.handleTouchEvents)
; it runs this.handleTouchEvents
method.
<template>
<v-app>
<v-main>
<v-container id="touch-container" fluid>
<div class="items">
...
</div>
</v-container>
</v-main>
</v-app>
</template>
<script>
export default {
mounted () {
const Hammer = require('hammerjs')
const touchContainer = document.getElementById('touch-container')
const hammer = new Hammer.Manager(touchContainer, {
recognizers: [
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }]
]
})
hammer.on('swipe', this.handleTouchEvents)
},
methods: {
handleTouchEvents (e) {
alert(e.type)
}
}
}
</script>
<style scoped>
#touch-container {
height: 100%;
min-width: 100%;
overflow-x: hidden;
}
#items {
touch-action: pan-y;
}
</style>
Any idea how to resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TouchContainer
可能是未定义的。2件事:
process.client
this。$ nexttick()
在此处尝试以下操作:
touchContainer
is probably undefined.2 Things:
process.client
this.$nextTick()
Here try this: