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', {
1111Vue . component ( 'rotator' , {
1212 template : `
1313 <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.
1724 </v-touch>
25+ {{$data}}
1826 </container>
1927 ` ,
2028 data ( ) {
2129 return {
22- angle : 0 ,
30+ startRotation : 0 ,
31+ currentRotation : 0 ,
2332 rotation : 0 ,
24- initialRotation : 0 ,
2533 name : ''
2634 }
2735 } ,
2836 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
3443
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
3948 }
4049 } ,
4150 computed : {
4251 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
4462 }
4563 }
4664} )
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ if (process.env.NODE_ENV === 'development') {
88else {
99 VueTouch = require ( '../dist/vue-touch.js' )
1010}
11- // import './styling.css'
12- // import './components '
13- // use the plugin
11+
12+ import './styling.css '
13+ import './components'
1414
1515// example registering a custom doubletap event.
1616// the `type` indicates the base recognizer to use from Hammer
@@ -34,11 +34,4 @@ new Vue({
3434 console . log ( e )
3535 }
3636 }
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 88 # test-div {
99 width : 300px ;
1010 height : 300px ;
11- background-color : # f00 ;
11+ background-color : orange ;
1212 }
1313 </ style >
1414 </ head >
1515 < body >
1616 < div id ="app ">
17- < v-touch tag ="div "
17+ <!-- < v-touch tag="div" id="test- div"
1818 @swipe="test"
1919 @doubletap="test"
2020 :doubletap-options="{taps: 3}"
2121 >
2222 <p>{{event.type}}</p>
23- </ v-touch >
23+ </v-touch> -->
2424 < pre > {{event}}</ pre >
2525
26- <!-- < rotator>
26+ < rotator >
2727 rotate me!
28- </rotator> -->
28+ </ rotator >
2929 </ div >
3030 < script src ="vendor.build.js "> </ script >
3131 < script src ="example.build.js "> </ script >
You can’t perform that action at this time.
0 commit comments