250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- css3
- ipad
- 풀스택
- php
- iOS 개발자
- hover
- jQuery
- 프론트엔드
- html5
- 자바스크립트
- 비전공자
- keyframes
- javascript
- 개발자
- image
- react
- CSS
- iPhone
- front-end
- 애니메이션
- HTML
- xcode
- 백엔드
- 비전공 개발자
- MAC
- Animation
- IOS
- effect
- button
- SWIFT
Archives
- Today
- Total
비전공자 개발일기
3D Card 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Card</title>
<link rel="stylesheet" href="style.css">
<script src="main.js"></script>
</head>
<body>
<div class="container">
<div class="card" id="card" onmousemove="transformation(event)" onmouseout="stablecard()">
<h3 class="title" id="title">TOKYO</h3>
</div>
</div>
</body>
</html>
body {
background-color: #000;
}
.container {
display: flex;
justify-content: center;
align-items: center;
perspective: 500px;
}
#card {
position: relative;
width: 250px;
height: 350px;
margin: 10%;
background: url("url") center no-repeat;
background-size: cover;
border: 2px solid violet;
border-radius: 10px;
transform-style: preserve-3d;
will-change: transform;
transition: all .5s ease-out;
}
.title {
color: violet;
position: absolute;
top: 40%;
right: 10px;
transform: translateY(-50%);
transition: transform .5s ease-in;
}
let elem = document.getElementById("card");
let elem1 = document.getElementById("title");
let rect = elem.getBoundingClientRect();
function transformation(event) {
let x = event.clientX;
let y = event.clientY;
console.log(x, y, rect.x, rect.y);
makeTransformation(x, y);
}
function makeTransformation(x, y) {
let x1 = x-(rect.x +(rect.width/2));
let y1 = y-(rect.y+(rect.height/2));
console.log(x-(rect.x+(rect.width/2)), y-(rect.y+(rect.height/2)));
console.log(Math.cos(x1) * 20, Math.cos(y1) * 20);
elem.style.transform = `translateZ(10px) rotateX(${x1/5}deg) rotateY(${y1/8}deg)`;
elem1.style.transform = `translateZ(50px)`
}
function stablecard() {
elem.style.transform = `translateZ(0px) rotateX(0deg) rotateY(0deg)`;
elem1.style.transform = `translateZ(0px)`
}
728x90
LIST
'Javascript' 카테고리의 다른 글
Lock Animation (0) | 2022.05.05 |
---|---|
Alarm Application (0) | 2022.05.02 |
Circle Loading Tape (0) | 2022.04.24 |
Age Calculator (0) | 2022.04.21 |
HAMBURGER ANIMATION (0) | 2022.04.18 |