This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (94 loc) · 2.26 KB
/
index.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<article class="card">
<div class="content">
<h2>Coming Soon</h2>
<p>uzairpatel.com</p>
</div>
</article>
<script>
const card = document.querySelector(".card");
const motionMatchMedia = window.matchMedia("(prefers-reduced-motion)");
const THRESHOLD = 15;
function handleHover(e) {
const { clientX, clientY, currentTarget } = e;
const { clientWidth, clientHeight, offsetLeft, offsetTop } = currentTarget;
const horizontal = (clientX - offsetLeft) / clientWidth;
const vertical = (clientY - offsetTop) / clientHeight;
const rotateX = (THRESHOLD / 2 - horizontal * THRESHOLD).toFixed(2);
const rotateY = (vertical * THRESHOLD - THRESHOLD / 2).toFixed(2);
card.style.transform = `perspective(${clientWidth}px) rotateX(${rotateY}deg) rotateY(${rotateX}deg) scale3d(1, 1, 1)`;
}
function resetStyles(e) {
card.style.transform = `perspective(${e.currentTarget.clientWidth}px) rotateX(0deg) rotateY(0deg)`;
}
if (!motionMatchMedia.matches) {
card.addEventListener("mousemove", handleHover);
card.addEventListener("mouseleave", resetStyles);
}
</script>
<style>
body {
background-color: rgb(66, 66, 66);
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
p {
margin-top: 0;
font-size: 20px;
}
a {
text-decoration: none;
}
h2 {
font-size: 42px;
margin-bottom: 15px;
}
button {
background: #e85757;
border: none;
border-radius: 30px;
cursor: pointer;
display: block;
font-size: 18px;
font-weight: 700;
padding: 16px;
width: 120px;
color: #fff;
}
.card {
background: url("src/card-bg.jpg") no-repeat;
background-size: cover;
max-width: 500px;
margin: auto;
height: auto;
padding: 40px;
position: relative;
color: #fff;
transition: transform 0.1s ease;
transform-style: preserve-3d;
will-change: transform;
}
.card::before {
content: "";
background: rgba(0, 0, 0, 0.4);
position: absolute;
height: 100%;
width: 100%;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
/* Slight parallax effect on hover */
.card:hover .content {
transform: translateZ(12px);
}
.content {
position: relative;
z-index: 1;
transition: transform 0.3s ease;
}
</style>