Reputation: 115
I have a off canvas menu on my mobile HTML site.
Its working good but slide effect working on just toggle-button. But I need swipe function on the menu. How can I add it?
JS:
$(function() {
// Toggle Nav on Click
$('.toggle-nav').click(function() {
// Calling a function in case you want to expand upon this.
toggleNav();
});
});
function toggleNav() {
if ($('#site-wrapper').hasClass('show-nav')) {
// Do things on Nav Close
$('#site-wrapper').removeClass('show-nav');
} else {
// Do things on Nav Open
$('#site-wrapper').addClass('show-nav');
}
}
Upvotes: 1
Views: 2129
Reputation: 2867
Simply listen to the swipe
event
$("#site-canvas").on("swipe", function() {
toggleNav();
});
Upvotes: 1
Reputation: 1006
Since you're using jQuery you can take advantage of the jQuery swipe event handler.
$(window).on("swipe", function(event){ ... })
.
Upvotes: 1