StyleSheet/CSS
CSS3 Menu Animation
jaiyah
2017. 2. 22. 15:00
CSS3 를 이용한 메뉴 애니메이션
Menu Animation Source
See the Pen 메뉴 애니메이션 by jaeheekim (@jaehee) on CodePen.
CSS Preview
css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 16px;
}
ul li {
list-style: none;
}
body {
position: relative;
display: flex;
justify-content: center;
align-items: center;
/* 100vh 이면 애니메이션 떨림, 현재 body 를 기준으로 메뉴 정렬을 시켜놨기 때문 */
min-height: 99.999vh;
background: #e0e0e0;
border: 20px solid #ffffff;
}
body:before {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 50%;
background: #D84315;
content: "";
}
.menu {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 70px;
width: 70px;
padding: 15px 20px;
background: #fff;
box-shadow: 0 4px 64px rgba(0, 0, 0, 0.2);
transition: 1.3s cubic-bezier(0.53, 0, 0.15, 1.3);
z-index: 2;
border-radius: 5px;
}
.menu.expanded {
width: 400px;
height: 80px;
}
.menu span {
/*white-space: nowrap;*/
visibility: visible;
opacity: 1;
transition: .3s;
transform: rotateY(0deg);
}
.menu a {
text-decoration: none;
text-transform: uppercase;
font-weight: bold;
color: #333;
padding: 5px;
transition: .3s;
}
.menu a:hover {
color: #D84315;
}
.menu span:nth-of-type(1) {
transition-delay: .4s;
}
.menu span:nth-of-type(2) {
transition-delay: .5s;
}
.menu span:nth-of-type(3) {
transition-delay: .6s;
}
.menu span:nth-of-type(4) {
transition-delay: .7s;
}
.menu span.hidden {
width: 0;
visibility: hidden;
opacity: 0;
transform: rotateY(90deg);
}
/* 숨김 처리시 마지막 메뉴부터 차례대로 보여지도록 delay 처리 */
.menu span.hidden:nth-of-type(1) {
transition-delay: .3s;
}
.menu span.hidden:nth-of-type(2) {
transition-delay: .2s;
}
.menu span.hidden:nth-of-type(3) {
transition-delay: .1s;
}
.menu span.hidden:nth-of-type(4) {
transition-delay: 0s;
}
.icon-menu {
order: 1;
position: relative;
display: flex;
/*flex-direction: row;*/
/*justify-content: space-between;*/
align-items: center;
width: 30px;
height: 34px;
padding: 5px;
cursor: pointer;
}
/* .icon, ::before, ::after 햄버거 메뉴 스타일 */
.icon-menu .icon {
position: relative;
width: 100%;
height: 2px;
background: #aaa;
}
.icon-menu .icon::before {
position: relative;
display: flex;
width: 100%;
height: 2px;
background: #aaa;
top:-7px;
content: "";
transition: top .25s ease, bottom .25s ease, transform .5s ease;
}
.icon-menu .icon::after {
position: relative;
display: flex;
bottom: -5px;
height: 2px;
width: 100%;
background: #aaa;
content: "";
transition: top .25s ease, bottom .25s ease, transform .5s ease;
}
.icon-menu:hover .icon:before {
top: -9px;
}
.icon-menu:hover .icon:after {
bottom: -7px;
}
/* X 닫기 버튼 스타일*/
.icon-menu .icon.close {
height: 0;
}
.icon-menu .icon.close::before {
transform: rotate(45deg);
top: 0;
}
.icon-menu .icon.close::after {
transform: rotate(-45deg);
bottom: 2px;
}
.icon-menu:hover .icon.close::before {
transform: rotate(405deg);
}
.icon-menu:hover .icon.close::after {
transform: rotate(315deg);
}
Jaehee's WebClub