Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unbind to destroy #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vue-hammer

fix ios 13 hammer scrolling on panmove
fix unbind destory

Hammer.js wrapper for Vue to support some operation in the mobile

This is a directive wrapper for Hammer.js 2.x. And this repo'inspiration is from v-touch.
Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const VueHammer = {
Vue.directive('hammer', {
bind: (el, binding) => {
if (!el.hammer) {
el.hammer = new Hammer.Manager(el)
el.hammer = new Hammer.Manager(el, { inputClass: Hammer.TouchMouseInput })
el.hammer.domEvents = true
}
const mc = el.hammer

Expand Down Expand Up @@ -130,10 +131,20 @@ export const VueHammer = {
if (mc.handler) {
el.hammer.off(eventWithDir, mc.handler)
}
if (!Object.keys(mc.handlers).length) {
let eventkeys = Object.keys(el.hammer.handlers)
let isDestroy = true
eventkeys.forEach(element => {
if (mc.handlers[element].length > 0)
{
isDestroy = false
}
})
if (isDestroy)
{
console.warn('[vue-hammer] unbind destroy')
el.hammer.destroy()
el.hammer = null
}
}
},
})
},
Expand Down