728x90
반응형
UpDown LeftRight Animation
마우스 오버에 따른 앞뒤로 돌고 옆으로 도는 애니메이션을 만들어 보았습니다.
CSS
/* font */
@font-face {
font-family: "LocusSangsang";
font-weight: normal;
font-style: normal;
src: url("https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.eot");
src: url("https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.eot?#iefix") format("embedded-opentype"),
url("https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.woff2") format("woff2"),
url("https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.woff") format("woff"),
url("https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.ttf") format("truetype");
font-display: swap;
}
body {
font-family: "LocusSangsang";
background-image: linear-gradient(135deg, #191970 0%, #483D8B 40%, #9370DB 100%);
height: 100vh;
}
.hover__wrap {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.hover__wrap > div {
max-width: 400px;
margin: 3%;
position: relative;
perspective: 300px;
}
.hover__wrap > div img {
width: 100%;
border: 10px solid #F0F8FF;
box-shadow: 2px 2px 2px 2px rgba(0,0,0,0.2);
box-sizing: border-box;
vertical-align: top;
}
.hover__wrap > div .front {
transition: transform 1s;
transform-style: preserve-3d; /*3d 공간에 넣어준다*/
}
.hover__wrap > div .back {
position: absolute;
left: 0;
top: 0;
z-index: -1;
transition: transform 1s;
transform-style: preserve-3d; /*3d 공간에 넣어준다*/
}
.hover__wrap > div figcaption {
background: rgba(0,0,0,0.4);
color: #F8F8FF;
padding: 10px;
text-align: center;
line-height: 1.5;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) translateZ(100px);
width: 60%;
backface-visibility: hidden;
}
/* mouse hover effect */
.hover__updown .front {
transform: rotateX(0deg);
}
.hover__updown:hover .front {
transform: rotateX(180deg);
backface-visibility: hidden; /*돌았을때 앞에 이미지가 사라진다.*/
}
.hover__updown .back {
transform: rotateX(-180deg);
}
.hover__updown:hover .back {
transform: rotateX(0deg);
}
.hover__leftright .front {
transform: rotateY(0deg);
}
.hover__leftright:hover .front {
transform: rotateY(180deg);
backface-visibility: hidden; /*돌았을때 앞에 이미지가 사라진다.*/
}
.hover__leftright .back {
transform: rotateY(-180deg);
}
.hover__leftright:hover .back {
transform: rotateY(0deg);
}
HTML
<body>
<div class="hover__wrap">
<div class="hover__updown">
<figure class="front">
<img src="https://github.com/thdtjdgml415/coding2/blob/main/animation/img/hoverLeft.png?raw=true" alt="">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 Up</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/thdtjdgml415/coding2/blob/main/animation/img/hoverRigth.png?raw=true" alt="">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 Down</p>
</figcaption>
</figure>
</div>
<div class="hover__leftright">
<figure class="front">
<img src="https://github.com/thdtjdgml415/coding2/blob/main/animation/img/hoverUP.png?raw=true" alt="">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 to Right</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/thdtjdgml415/coding2/blob/main/animation/img/hoverDown.png?raw=true"
alt="">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 to Left</p>
</figcaption>
</figure>
</div>
</div>
</body>
사이트 결과
결과
반응형
'CSS' 카테고리의 다른 글
CSS활용 - stroke (7) | 2022.09.07 |
---|---|
CSS활용 - animation (9) | 2022.09.07 |
SVG - intro (4) | 2022.09.07 |
CSS 요소를 숨기는 5가지 방법 (8) | 2022.08.25 |
색상 표현 단위 (6) | 2022.08.23 |