This repository was archived by the owner on Dec 26, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +42
-31
lines changed Expand file tree Collapse file tree 3 files changed +42
-31
lines changed Original file line number Diff line number Diff line change @@ -11,36 +11,54 @@ Vue.component('container', {
11
11
Vue . component ( 'rotator' , {
12
12
template : `
13
13
<container>
14
- <v-touch @rotate="cb" :rotate-options="{threshold: 15}" :style="rotated" class="rotator">
15
- <slot></slot>
16
- {{name || 'NoEvent'}} - {{angle}}deg, {{rotation}}
14
+ <v-touch
15
+ @rotatestart="start"
16
+ @rotate="rotate"
17
+ @doubletap="reset"
18
+ :rotate-options="{threshold: 15}"
19
+ style="text-align: center; padding-top: 30px;" :style="rotated" class="rotator"
20
+ >
21
+ <slot></slot><br>
22
+ This element is rotated {{rotation | round(2) }} deg<br>
23
+ Double-tap to reset.
17
24
</v-touch>
25
+ {{$data}}
18
26
</container>
19
27
` ,
20
28
data ( ) {
21
29
return {
22
- angle : 0 ,
30
+ startRotation : 0 ,
31
+ currentRotation : 0 ,
23
32
rotation : 0 ,
24
- initialRotation : 0 ,
25
33
name : ''
26
34
}
27
35
} ,
28
36
methods : {
29
- cb ( event ) {
30
- console . log ( 'rotate' , event )
31
- if ( event . isFirst ) { this . initialRotation = event . rotation }
32
- else {
33
- const newRotation = Math . round ( event . rotation - this . initialRotation )
37
+ start ( e ) {
38
+ this . startRotation = e . rotation < 0 ? 360 + e . rotaton : e . rotation
39
+ this . name = e . type
40
+ } ,
41
+ rotate ( e ) {
42
+ this . currentRotation = e . rotation < 0 ? 360 + e . rotation : e . rotation
34
43
35
- this . rotation = this . rotation = newRotation
36
- }
37
- this . angle = Math . round ( event . angle )
38
- this . name = event . type
44
+ } ,
45
+ reset ( ) {
46
+ this . currentRotation = 0
47
+ this . startRotation = 0
39
48
}
40
49
} ,
41
50
computed : {
42
51
rotated ( ) {
43
- return { transform : `rotate(${ this . rotation } deg)` }
52
+ const { currentRotation : current , startRotation : start } = this . $data
53
+ const real = current - start
54
+ this . rotation = real
55
+ return { transform : `rotate(${ real } deg)` }
56
+ }
57
+ } ,
58
+ filters : {
59
+ round ( n , dec = 0 ) {
60
+ const f = Math . pow ( 10 , dec )
61
+ return Math . round ( n * f ) / f
44
62
}
45
63
}
46
64
} )
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ if (process.env.NODE_ENV === 'development') {
8
8
else {
9
9
VueTouch = require ( '../dist/vue-touch.js' )
10
10
}
11
- // import './styling.css'
12
- // import './components '
13
- // use the plugin
11
+
12
+ import './styling.css '
13
+ import './components'
14
14
15
15
// example registering a custom doubletap event.
16
16
// the `type` indicates the base recognizer to use from Hammer
@@ -34,11 +34,4 @@ new Vue({
34
34
console . log ( e )
35
35
}
36
36
}
37
- }
38
-
39
- new Vue ( {
40
- components : { app : App } ,
41
- render ( h ) {
42
- return h ( App )
43
- }
44
- } ) . $mount ( '#app' )
37
+ } )
Original file line number Diff line number Diff line change 8
8
# test-div {
9
9
width : 300px ;
10
10
height : 300px ;
11
- background-color : # f00 ;
11
+ background-color : orange ;
12
12
}
13
13
</ style >
14
14
</ head >
15
15
< body >
16
16
< div id ="app ">
17
- < v-touch tag ="div "
17
+ <!-- < v-touch tag="div" id="test- div"
18
18
@swipe="test"
19
19
@doubletap="test"
20
20
:doubletap-options="{taps: 3}"
21
21
>
22
22
<p>{{event.type}}</p>
23
- </ v-touch >
23
+ </v-touch> -->
24
24
< pre > {{event}}</ pre >
25
25
26
- <!-- < rotator>
26
+ < rotator >
27
27
rotate me!
28
- </rotator> -->
28
+ </ rotator >
29
29
</ div >
30
30
< script src ="vendor.build.js "> </ script >
31
31
< script src ="example.build.js "> </ script >
You can’t perform that action at this time.
0 commit comments