You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 26, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+63-48Lines changed: 63 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,14 @@ This is a component wrapper for Hammer.js 2.0.
8
8
9
9
> This plugin requires Vue >= 2.0. For the Vue 1.\*-compatible version, see the `1.0` branch
10
10
11
-
#### CommonJS
12
11
13
12
- Available through npm as `vue-touch`.
14
13
15
-
```js
16
-
varHammer=require('hammerjs')
17
-
varVueTouch=require('vue-touch')
18
-
Vue.use(VueTouch, {hammer: Hammer})
19
-
```
14
+
```Javascript
15
+
varVueTouch=require('vue-touch')
16
+
Vue.use(VueTouch, {name:'v-touch'})
17
+
```
18
+
You can pass an options object as the second argument, which at the moment accepts one property, `name`. It's used to define the name of the component that is registered with Vue and defaults to `'v-touch'`.
20
19
21
20
#### Direct include
22
21
@@ -36,7 +35,7 @@ This is a component wrapper for Hammer.js 2.0.
36
35
37
36
## API
38
37
39
-
### Events
38
+
### Component Events
40
39
41
40
vue-touch supports all Hammer Events ot of the box, just bind a listener to the component with `v-on` and vue-touch will setup the Hammer Manager & Recognizer for you.
42
41
@@ -49,22 +48,9 @@ vue-touch supports all Hammer Events ot of the box, just bind a listener to the
There are two ways to customize recognizer options such as `direction` and `threshold`.
55
-
56
-
#### Defining Global Options
57
-
58
-
```js
59
-
// change the threshold for all swipe recognizers
60
-
VueTouch.config.swipe= {
61
-
threshold:200
62
-
}
63
-
```
64
-
65
-
#### Passing Options as props
51
+
### Component Props
66
52
67
-
Or, you can use the matching `*-options` props to configure the behavior on a specific element:
53
+
You can use the matching `*-options` props to pass Hammer options such as `direction` and `threshold`:
68
54
69
55
```html
70
56
<!-- detect only horizontal pans with a threshold of 100 -->
@@ -83,40 +69,21 @@ There's one prop per `Recognizer` available.
83
69
|**Swipe**|`v-bind:swipe-options`|
84
70
|**Tap**|`v-bind:tap-options`|
85
71
86
-
87
-
These options will overwrite globally defined ones.
88
-
89
72
See [Hammer.js documentation](http://hammerjs.github.io/getting-started/) for all available options for events.
90
73
91
-
##Registering Custom Events
74
+
#### Directions
92
75
93
-
You can register custom events with vue-touch.
94
-
95
-
```js
96
-
// example registering a custom doubletap event.
97
-
// the `type` indicates the base recognizer to use from Hammer
98
-
// all other options are Hammer recognizer options.
99
-
VueTouch.registerCustomEvent('doubletap', {
100
-
type:'tap',
101
-
taps:2
102
-
})
103
-
```
104
-
> **Warning**: You have to register your custom events *before* installing the plugin with `Vue.use(VueTouch)`.
105
-
VueTouch will log a warning to the console (in dev mode) if you try to do that afterwards, and the event will not work.
76
+
In the above example, not that we used `direction: 'horizontal'`. Hammer's directions interface is a little ugly (Hammer['DIRECTION_HORIZONTAL']).
106
77
107
-
This will make it possible to listen for this event on `<v-touch>`. Additionally, just like for "normal" events, you can pass further options as the corresponding prop.
78
+
VueTouch keeps that from you and accepts simple strings as directions:
See `/example` for a multi-event demo. To build it, run `npm install && npm run build`.
84
+
## Public Component Methods
116
85
117
-
## Public Methods
118
-
119
-
The vue-touch exposes a few convenience methods to enable and disable Recognizers:
86
+
The component exposes a few convenience methods to enable and disable Recognizers:
120
87
121
88
|Method|Explanation|
122
89
|------|-----------|
@@ -144,6 +111,54 @@ The vue-touch exposes a few convenience methods to enable and disable Recognizer
144
111
</script>
145
112
```
146
113
114
+
### Plugin Methods
115
+
116
+
#### Global Event Options
117
+
118
+
You can define global defaults for the builtin recognizers
119
+
120
+
```js
121
+
// change the threshold for all swipe recognizers
122
+
VueTouch.config.swipe= {
123
+
threshold:200
124
+
}
125
+
```
126
+
127
+
#### Registering Custom Events
128
+
129
+
You can register custom events with vue-touch.
130
+
131
+
```js
132
+
// example registering a custom doubletap event.
133
+
// the `type` indicates the base recognizer to use from Hammer
134
+
// all other options are Hammer recognizer options.
135
+
VueTouch.registerCustomEvent('doubletap', {
136
+
type:'tap',
137
+
taps:2
138
+
})
139
+
```
140
+
> **Warning**: You have to register your custom events *before* installing the plugin with `Vue.use(VueTouch)`.
141
+
VueTouch will log a warning to the console (in dev mode) if you try to do that afterwards, and the event will not work.
142
+
143
+
This will make it possible to listen for this event on `<v-touch>`. Additionally, just like for "normal" events, you can pass further options as the corresponding prop.
0 commit comments