CSS 애니메이션 연습하기
마우스 오버 효과에 3D를 간단하게 첨가해서 멋진 애니메이션 효과를 만들어 보겠습니다.
결과
HTML
사진4장을 각각 두장씩 한 태그로 묶어서 만들어줍니다.
<div class="hover__wrap">
<div class="hover__updown">
<figure class="front">
<img src="https://github.com/younghwan12/coding3/blob/main/animation/img/homeup.jpg?raw=true" alt="계란 후라이">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 Up</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/younghwan12/coding3/blob/main/animation/img/homedown.jpg?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/younghwan12/coding3/blob/main/animation/img/homeright.jpg?raw=true" alt="깨진 계란">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 to Right</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/younghwan12/coding3/blob/main/animation/img/homeleft.jpg?raw=true
" alt="깨진 계란">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 내리면 to Left</p>
</figcaption>
</figure>
</div>
</div>
CSS
사진 두장을 앞뒤로 겹치고 뒤집었을때 뒷면을 안보이게 설정합니다.
@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, yellowgreen 0%, blueviolet 40%, gold 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: 1000px;
}
.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;
backface-visibility: hidden;
transform-style: preserve-3d;
}
.hover__wrap > div .back {
position: absolute;
left: 0;
top: 0;
z-index: -1;
transition: transform 1s;
transform-style: preserve-3d;
}
.hover__wrap > div .right {
position: absolute;
left: 0;
top: 0;
z-index: -1;
}
.hover__wrap > div figcaption {
background: rgba(0,0,0,0.2);
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);
}
.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);
}
.hover__leftright .back {
transform: rotateY(-180deg);
}
.hover__leftright:hover .back {
transform: rotateY(0deg);
}
새로배운 코드
backface-visibility: hidden; //뒷면은 안보이게 한다.
perspective: 1000px; //원근법 설정 숫자가 작을수록 원근법효과가 커진다.
transform: translatez(100px); //Z축으로 100px 떨어트린다(3D)
'CSS' 카테고리의 다른 글
CSS 애니메이션 - 3D cube (6) | 2022.09.22 |
---|---|
CSS 애니메이션 - (기름에튀기는 글자 (9) | 2022.09.21 |
CSS 애니메이션 - 꿀렁이는 원 (6) | 2022.09.19 |
CSS 애니메이션 - 걷기 애니메이션 (16) | 2022.09.07 |
CSS - 애니메이션의 모든것 (10) | 2022.09.07 |
댓글