Skip to content

Commit 03eccd0

Browse files
morigschrisvfritz
authored andcommitted
toggle sidebar by swipe (#767)
1 parent 118a032 commit 03eccd0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

themes/vue/source/js/common.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
}
9292

9393
/**
94-
* Mobile burger menu button for toggling sidebar
94+
* Mobile burger menu button and gesture for toggling sidebar
9595
*/
9696

9797
function initMobileMenu () {
@@ -108,6 +108,27 @@
108108
sidebar.classList.remove('open')
109109
}
110110
})
111+
112+
// Toggle sidebar on swipe
113+
var start = {}, end = {}
114+
115+
document.body.addEventListener('touchstart', function (e) {
116+
start.x = e.changedTouches[0].clientX
117+
start.y = e.changedTouches[0].clientY
118+
})
119+
120+
document.body.addEventListener('touchend', function (e) {
121+
end.y = e.changedTouches[0].clientY
122+
end.x = e.changedTouches[0].clientX
123+
124+
var xDiff = end.x - start.x
125+
var yDiff = end.y - start.y
126+
127+
if (Math.abs(xDiff) > Math.abs(yDiff)) {
128+
if (xDiff > 0) sidebar.classList.add('open')
129+
else sidebar.classList.remove('open')
130+
}
131+
})
111132
}
112133

113134
/**

0 commit comments

Comments
 (0)