Folding Content Nav Menu CSS3 Animation JavaScript Tutorial
Learn to create various folding content effects with click triggers and toggle mechanisms. Learning these visual effects can greatly enhance your front-end design work. The best part is that it's so simple to do, that no 3rd party frameworks or libraries are needed. The code is slim, and the visual effects are awesome.
example.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { margin: 0px; }
#topbar { background: #555; height: 70px; }
#menu1btn { float:left; margin:15px 0px 0px 20px; padding: 10px; }
#menu1 {
position: absolute;
left: 20px;
background: #333;
width: 140px;
height: auto;
padding: 0px 2px 2px 2px;
z-index: 10;
transform-origin: 50% 0%;
transform: perspective(800px) rotateX(90deg);
transition: transform .3s linear 0s;
}
#menu1 > a {
display: block;
text-decoration: none;
color: #FFF;
background:#666;
padding: 12px 0px 12px 12px;
margin: 1px;
font-family: Arial;
font-size: 13px;
transition: background 0.2s linear 0s, color 0.2s linear 0s;
}
#menu1 > a:hover { background:#888; color:#FFF; }
</style>
<script>
function toggleMenu(menu){
var menu = document.getElementById(menu);
if(menu.dataset.opened == "no"){
menu.style.transform = "perspective(800px) rotateX(0deg)";
menu.dataset.opened = "yes";
return false;
} else {
menu.style.transform = "perspective(800px) rotateX(90deg)";
menu.dataset.opened = "no";
}
}
</script>
</head>
<body>
<div id="topbar">
<button id="menu1btn" onclick="toggleMenu('menu1')">Menu</button>
</div>
<nav id="menu1" class="folding_menu" data-opened="no">
<a href="#">Section A</a>
<a href="#">Section B</a>
<a href="#">Section C</a>
<a href="#">Section D</a>
</nav>
</body>
</html>