-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
112 lines (96 loc) · 3.19 KB
/
script.js
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
const layer = document.getElementById("layer");
let typed = new Typed("#text", {
strings: ["Harsh", "Developer", "Designer", "Coder"],
typeSpeed: 200,
backSpeed: 100,
backDelay: 1000,
loop: true,
loopCount: Infinity,
});
const home = document.querySelector(".home");
const about = document.querySelector(".about");
const work = document.querySelector(".work");
const contact = document.querySelector(".contact");
const a2 = document.getElementById("about");
const w2 = document.getElementById("work");
const wl = document.querySelector(".work .line");
const line = document.querySelector(".line");
const line2 = document.querySelector(".line2");
const footer = document.querySelector(".footer");
function night() {
home.classList.toggle("night");
about.classList.toggle("night");
work.classList.toggle("night");
contact.classList.toggle("night");
footer.classList.toggle("night");
}
a2.addEventListener("click", () => {
line.classList.add("lineactive");
setTimeout(() => {
line.classList.remove("lineactive");
}, 5000);
});
w2.addEventListener("click", () => {
wl.classList.add("lineactive");
line2.classList.add("line2active");
setTimeout(() => {
wl.classList.remove("lineactive");
}, 5000);
setTimeout(() => {
line2.classList.remove("line2active");
}, 6220);
});
function hire() {
setTimeout(() => {
scrollTo(0, 2238);
}, 1000);
}
const btn = document.querySelectorAll("header li a, button");
for (const button of btn) {
button.addEventListener("click", (e) => {
e.preventDefault();
var layerClass = ".right-layer";
var layers = document.querySelectorAll(layerClass);
for (const layer of layers) {
layer.classList.toggle("active");
setTimeout(() => {
layer.classList.remove("active");
}, 900);
}
setTimeout(() => {
const sectionId = button.getAttribute("href").substring(1);
const section = document.getElementById(sectionId);
if (sectionId === "about") {
window.scrollTo(0, 746);
} else if (sectionId === "work") {
window.scrollTo(0, 1492);
} else if (sectionId === "contact") {
window.scrollTo(0, 2238);
} else {
window.scrollTo(0, 0);
}
}, 1500);
});
}
// workpage
const cards = document.querySelectorAll(".card");
for (const card of cards) {
const motion = 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 (!motion.matches) {
card.addEventListener("mousemove", handleHover);
card.addEventListener("mouseleave", resetStyles);
}
}