I've been searching all over and still no solution to this. I have a vertical menu and by default is expanded. When i click on the toogle button as in the image below, it adds the verical-mini class to the body tag, and also is saving it inside localstorage, which represents the collapsed state.
Now the issue i have is that on poor internet connections screens, or chrome and edge browsers on page load/refresh , it displays first the default expanded class and only after document has been loaded , if the mini class exists in localstorage , it adds the vertical-mini class to the body tag.
So is it possible to load the saved class from localstorage before anything else, or at least faster so we can't see the default expanded state first ?
I tried also placing the jquery inside the header but still has the same delay.
Someone suggested me a jquery preloader but this is not an alternative as some of my pages have a lot of content and it would take some time until the document will be loaded.
jQuery code:
$(document).ready(function() {
$('.vertical-menu-toogle').click(function (event) {
event.preventDefault();
$('body').toggleClass('vertical-mini');
if($('body').hasClass('vertical-mini')){
localStorage.setItem('savedmini', 'vertical-mini');
}
else{
localStorage.removeItem('savedmini');
}
});
var savedmini = localStorage.getItem('savedmini');
if(savedmini !== ''){
$('body').addClass(savedmini);
}
else {
$('body').removeClass(savedmini);
}
});
CSS:
.vertical-menu {
height: 100%;
width: 250px;
}
.vertical-mini .vertical-menu {
width: 80px;
}