I am currently working on developing a custom off-canvas navigation system that is similar to the functionality of Foundation. Essentially, I have 2 icons that trigger CSS adjustments when clicked. I am contemplating whether it is feasible to streamline the code by consolidating these actions into a single toggle function rather than having separate functions for opening and closing with distinct divs. This is the current setup I am working with:
jQuery(".navMenuOpen").click(function(event) {
event.preventDefault();
jQuery(".page-wrapper").css("left", "70%");
jQuery(".off-canvas-nav").css("left", "0")
jQuery(".navMenuOpen").css("display", "none");
jQuery(".navMenuClose").css("display", "block");
});
jQuery(".navMenuClose").click(function(event) {
event.preventDefault();
jQuery(".page-wrapper").css("left", "0");
jQuery(".off-canvas-nav").css("left", "-100%")
jQuery(".navMenuOpen").css("display", "block");
jQuery(".navMenuClose").css("display", "none");
});
My question is: Is there a way to simplify this process down to a single function/HTML element?
Thank you in advance!