I'm trying to close an off canvas navigation panel by clicking on a link in that panel. You can open/close the panel with a hamburger button and close it when you click anywhere on the page.
See: http://whyyouthinking.com/xindex.html#what
I got to the point where it was working but the hamburger had to be clicked twice to work again.
$(document).ready(function () {
"use strict";
$('.panel ul li a').on("click", function () {
$('.menu-link').removeClass("active");
$('.panel').animate({left: '-=250'});
});
});
I've got round that with:
$(document).ready(function () {
"use strict";
$('.panel ul li a').on("click", function () {
$('.menu-link').removeClass("active");
$('.panel').animate({left: '-=250'});
});
$('.panel ul li a').on('click', function(e) {
e.preventDefault();
$('.menu-link').click();
});
});
Now I have the problem that the e.preventDefault(); is also stopping my 'scrollto' function, when you click on a link in the panel. Is there a way of just targeting the .menu-link?