<style>
* {
padding: 0;
margin: 0;
}
body {
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
}
nav {
width: 400px;
height: 100vh;
overflow: hidden;
}
#menu li {
font-size: 22px;
padding: 10px 0;
list-style: none;
}
#menu li a {
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
#menu li a:hover {
color: tomato;
}
#menu {
width: 400px;
height: 100vh;
background: #ededed;
margin: -80px 0 0 -50px;
padding: 100px 0 0 50px;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menuToggle {
margin: 50px 0 0 50px;
}
#menuToggle span {
display: block;
width: 32px;
height: 5px;
background: #cdcdcd;
border-radius: 3px;
margin-bottom: 5px;
position: relative;
z-index: 2;
transform-origin: 0;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
opacity 0.4s ease;
}
#menuToggle input {
width: 40px;
height: 30px;
cursor: pointer;
opacity: 0;
position: absolute;
z-index: 3;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menuToggle input:checked ~ #menu {
transform: none;
}
#menuToggle input:checked ~ span {
background: #232323;
}
#menuToggle input:checked ~ span:nth-child(2) {
transform: rotate(45deg) translate(-3px);
}
#menuToggle input:checked ~ span:nth-child(3) {
opacity: 0;
transform: scale(0.2, 0.2);
}
#menuToggle input:checked ~ span:nth-child(4) {
transform: rotate(-45deg) translate(-1px,-1px);
}
</style>
<nav>
<div id="menuToggle">
<input type="checkbox"/>
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li><a href="javascript:;">Home</a></li>
<li><a href="javascript:;">About</a></li>
<li><a href="javascript:;">Info</a></li>
<li><a href="javascript:;">Contact</a></li>
<li><a href="javascript:;">Show me more</a></li>
</ul>
</div>
</nav>
transform:向元素应用2D或3D转换。该属性允许对元素进行旋转、缩放、移动或倾斜。
transition:监听属性值变化,并设置过渡效果,在属性之变动改变时触发。
animation:搭配@keyframse定义的一组动画指令集合,在duration时间的不同百分比时触发对应时间的CSS样式变动。具体更细节的值设定可以参考这里:Click me
transform-origin:设置旋转元素的基点位置。适用transform: rotate(…deg)时。