I've been searching how to auto-close off-canvas menu after some menu item is clicked but nothing seems to work.
So I followed guide on how to make off-canvas menu on Foundation 6 docs and it works. This part is okay. Now when I click on some link menu just stays there and I want it to close. Does anyone know how to fix that.
I've found snippet that should do the trick but my menu stops showing after I appy this JS. Others report the same problem.
$(document).foundation({
offcanvas : {
open_method: 'move', // Sets method in which offcanvas opens, can also be 'overlap'
close_on_click : true
}
});
Here are the docs, but since I don't know much about JavaScript I beg someone to write correct code.
You could use the close
method on the .off-canvas
menu when a link is clicked:
$('.off-canvas a').on('click', function() {
$('.off-canvas').foundation('close');
});
Click Here for a demo.