File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 92
92
}
93
93
94
94
/**
95
- * Mobile burger menu button for toggling sidebar
95
+ * Mobile burger menu button and gesture for toggling sidebar
96
96
*/
97
97
98
98
function initMobileMenu ( ) {
109
109
sidebar . classList . remove ( 'open' )
110
110
}
111
111
} )
112
+
113
+ // Toggle sidebar on swipe
114
+ var start = { } , end = { }
115
+
116
+ document . body . addEventListener ( 'touchstart' , function ( e ) {
117
+ start . x = e . changedTouches [ 0 ] . clientX
118
+ start . y = e . changedTouches [ 0 ] . clientY
119
+ } )
120
+
121
+ document . body . addEventListener ( 'touchend' , function ( e ) {
122
+ end . y = e . changedTouches [ 0 ] . clientY
123
+ end . x = e . changedTouches [ 0 ] . clientX
124
+
125
+ var xDiff = end . x - start . x
126
+ var yDiff = end . y - start . y
127
+
128
+ if ( Math . abs ( xDiff ) > Math . abs ( yDiff ) ) {
129
+ if ( xDiff > 0 ) sidebar . classList . add ( 'open' )
130
+ else sidebar . classList . remove ( 'open' )
131
+ }
132
+ } )
112
133
}
113
134
114
135
/**
You can’t perform that action at this time.
0 commit comments