I have created a sleek sliding navigation panel for my website that appears when the screen width is reduced. Although I am satisfied with how it functions currently, I would like the panel to close when the user clicks/taps outside of it. What adjustments should I make to my jQuery script in order to achieve this? (I consider myself a beginner when it comes to jQuery)
Website:
Here is the jQuery code snippet:
$(document).ready(function() {
$panel = $("#panel");
$tab = $("#tab");
$menu_icon = $("#menu_icon");
$tab.mousedown(function() {
var currentPanelPosition = $panel.css("left");
var newPanelPosition;
if (currentPanelPosition === "0px") {
newPanelPosition = "-200px";
$menu_icon.css("background-position-y", "0px");
} else {
newPanelPosition = "0px";
$menu_icon.css("background-position-y", "-40px");
}
$panel.animate({"left" : newPanelPosition}, 400, "easeOutExpo");
});
});