728x90
반응형
Mouse Hover Effect
마우스를 올리고 내렸을때 움직임이 생기는 효과를 만들어봅시다.
HTML
hover__wrap 안에 hover__updown, hover__leftright등 구조를 만들어줍니다.
<div class="hover__wrap">
<div class="hover__updown">
<figure class="front">
<img src="https://github.com/kimyihyung/coding/blob/main/animation/img/jpg1.jpg?raw=true" alt="지구">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 Up</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/kimyihyung/coding/blob/main/animation/img/jpg2.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/kimyihyung/coding/blob/main/animation/img/jpg3.jpg?raw=true" alt="산">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 올리면 to Right</p>
</figcaption>
</figure>
<figure class="back">
<img src="https://github.com/kimyihyung/coding/blob/main/animation/img/jpg4.jpg?raw=true" alt="구름">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>마우스 내리면 to Left</p>
</figcaption>
</figure>
</div>
</div>
CSS
perspective = 원근감 수치를 작게 입력할 수록 가깝게
transform-style: preserve-3d; 입력하면 z축 부여가능
@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: 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: 1000px;
/* perspective 원근감 숫자 적을 수록 가깝 */
}
.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 figcaption {
background: rgba(0, 0, 0, 0.4);
color: #F8F8FF;
padding: 10px;
text-align: center;
line-height: 0.7;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) translatez(100px);
/* translatez(100px)는 3D 효과를 주기 위한 transform-style 입력 후에 적어줌 */
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);
}
결과
See the Pen MouseHoverEffect by kimyihyung (@kimyihyung) on CodePen.
728x90
반응형
'CSS' 카테고리의 다른 글
growing box Animation (6) | 2022.09.22 |
---|---|
Text Wave Animation (3) | 2022.09.21 |
Wave Animation (5) | 2022.09.19 |
CSS - animation (7) | 2022.09.08 |
CSS - intro (8) | 2022.09.07 |