I have the following HTML code:
<body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white page-sidebar-closed" style="background-color: #F5F5F5">
When the page loads, the sidebar closed CSS will be applied.
Currently, I am using jQuery and HTML storage to save and retrieve the toggle value of the navigation bar.
var sidebar = $('.page-sidebar');
var sidebarMenu = $('.page-sidebar-menu');
var body = $('body');
if (localStorage.getItem("toggler") == 'close')
{
body.addClass("page-sidebar-closed");
sidebarMenu.addClass("page-sidebar-menu-closed");
}
else
{
body.removeClass("page-sidebar-closed");
sidebarMenu.removeClass("page-sidebar-menu-closed");
}
My issue is that when the page loads, it always loads with a closed sidebar. This isn't a problem if the user has clicked "Closed" and that choice is stored in local storage - the page then loads correctly with the sidebar closed.
However, if the user has clicked "Open", the page first loads with a closed sidebar because it is given the class 'page-sidebar-closed'. Then, the jQuery function opens it, resulting in a flicker of the sidebar whenever the page loads - toggling between closed and open.
Is there a way to directly apply a function on a class?