So, I was just making some tests for a little menu idea.
The idea is just to have a little dot in the top left corner of the screen.
When overing it will have a box shadow that make it look bigger, on click it will expand (width: 100%, height: 100%), after that a hidden div of the same color will show up.
And this will open the menu, by clicking the close button (CHIUDI) the menu will close, but then the hover property of the dot in the corner of the screen will no longer work.
I think this happen because I'm using JavaScript to modify CSS rules, and when I use the function to close the menu i will set the box-shadow to 0.
Probably this is the problem, because I think that this affect the :hover CSS property.
Is there anyway to fix this by using pure JavaScript? (No jQuery).
Here is the code:
<html>
<head>
<title>Design Tests</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Raleway:200');
#button {
position: fixed;
width: 50px;
height: 50px;
background-color: blue;
border-radius: 25px;
transition-duration: 500ms;
z-index: 1;
cursor: pointer;
}
#button:hover {
box-shadow: 0px 0px 0px 30px rgba(0, 0, 255, 1);
}
#menu_container {
position: fixed;
width: 100%;
height: 100%;
top: 0;
right: 0;
left: 0;
bottom: 0;
background-color: rgba(0, 0, 255, 1);
z-index: 0;
visibility: hidden;
}
#menu {
transition-duration: 500ms;
opacity: 0;
}
#close_menu {
color: white;
font-family: raleway;
cursor: pointer;
}
</style>
</head>
<body>
<div id="button" onclick="openMenu()"></div>
<div id="menu_container">
<div id="menu">
<center>
<h1 id="close_menu" onclick="closeMenu()">CHIUDI</h1>
</center>
</div>
</div>
<script>
function openMenu() {
document.getElementById('button').style.boxShadow = '0px 0px 0px 100em rgba(0,0,255,1)';
setTimeout(showMenu, 500);
}
function showMenu() {
document.getElementById('menu_container').style.visibility = 'visible';
document.getElementById('menu_container').style.zIndex = '2';
document.getElementById('menu').style.opacity = '1';
}
function closeMenu() {
document.getElementById('menu').style.opacity = '0';
setTimeout(hideMenu, 400);
}
function hideMenu() {
document.getElementById('menu_container').style.visibility = 'hidden';
document.getElementById('menu_container').style.zIndex = '0';
document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,1)';
}
</script>
</body>
</html>
-UPDATE-
I tried to use the CSS !important property, but it won't work.
Use the !important rules means that JavaScript won't affect that rules (if I'm right), but JavaScript need to edit that because he need to use box-shadow for make the animation itself.
Basically, using !important in the box-shadow hover rules, I will fix this bug, but when I'll open the menu I won't more see the animation.