I'm trying to use Javascript to accomplish two effects: 1) Make the description of navigation links in a menu on the left side of the page fly in from the left when hovering over the icon and fly back out when the mouse is no longer over the icon. 2) Give the user the ability to hide the menu with a button.
I have all the code in a codepen at this link... https://codepen.io/anon/pen/JemLER
Effect #1 is working perfectly until the menu is hidden with effect #2. Then, the descriptions will no longer fly in from the left side when the icon is hovered.
The way I am doing #1 is by using javascript to add or remove a class to the element that translates it to the left off of the page using mouseenter and mouseout event listeners.
Here are the javascript functions...
document.querySelector('.home-icon').addEventListener('mouseenter', () => {
document.querySelector('.home-desc').classList.remove('side-menu__list-item-desc-hide');
console.log('hover');
});
document.querySelector('.home-icon').addEventListener('mouseout', () => {
document.querySelector('.home-desc').classList.add('side-menu__list-item-desc-hide');
});
And this is the class to hide the elements.
.side-menu__list-item-desc-hide {
transform: translateX(-10rem);
}
For #2, I am hiding the menu in a similar way with a click event instead.
The javascript code is ...
const foldBtn = document.querySelector('.side-menu__fold-btn');
let isHidden = false;
foldBtn.addEventListener('click', () => {
if (isHidden == false) {
sideMenu.classList.add('side-menu-hide');
sideMenuList.innerHTML = '';
isHidden = true;
foldIcon.innerHTML = 'chevron_right';
}
else {
sideMenu.classList.remove('side-menu-hide');
isHidden = false;
foldIcon.innerHTML = 'chevron_left';
setTimeout(() => {
sideMenuList.innerHTML = sideMenuListContent;
}, 400);
}
});
And the CSS class is...
.side-menu-hide {
transform: translateX(-100%);
}
Any ideas what could be causing the problem?
Thanks!