12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import Hammer from 'hammerjs'
- export const HammerMixins = {
- data () {
- return {
- hammerManager: null,
- hasHammertap: false,
- hasHammerPan: false,
- hasHammerPinch: false
- }
- },
- methods: {
- initHammerTargrt (target, { tap, pan, pinch }) {
- this.hammerManager = new Hammer.Manager(target)
- const hammerTap = new Hammer.Tap({ pointers: 1 })
- const hammerPan = new Hammer.Pan({ pointers: 1 })
- const hammerPinch = new Hammer.Pinch({ pointers: 2 })
- let opts = []
- this.hasHammertap = tap
- this.hasHammerPan = pan
- this.hasHammerPinch = pinch
- if (tap) opts.push(hammerTap)
- if (pan) opts.push(hammerPan)
- if (pinch) opts.push(hammerPinch)
- this.hammerManager.add(opts)
- this.initHammerEvent()
- },
- initHammerEvent () {
-
- if (this.hasHammertap) {
- this.hammerManager.on(`tap`, (ev) => {
- ev.preventDefault()
- this.visible = false
- })
- }
-
- this.hammerManager.on(`panstart panmove panend tap, multitap`, (ev) => {
- ev.preventDefault()
- })
-
- this.hammerManager.on(`pinchmove pinchin pinchout pinchend`, (ev) => {
- ev.preventDefault()
- })
- }
- }
- }
|