-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (76 loc) · 3.07 KB
/
script.js
File metadata and controls
83 lines (76 loc) · 3.07 KB
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
document.addEventListener("DOMContentLoaded", function () {
try {
const buttons = document.querySelectorAll("button");
buttons.forEach((btn) => {
btn.addEventListener("mousedown", (e) => {
(e.currentTarget || btn).style.transform = "scale(0.96)";
});
btn.addEventListener("mouseup", (e) => {
(e.currentTarget || btn).style.transform = "scale(1)";
});
btn.addEventListener("mouseleave", (e) => {
(e.currentTarget || btn).style.transform = "scale(1)";
});
});
const onlineBtn = document.getElementById("online-compiler-btn");
if (onlineBtn) {
onlineBtn.addEventListener("click", function (e) {
e.preventDefault();
window.open("/compiler", "_blank");
});
}
const cube = document.querySelector(".cube3d-inner");
if (cube) {
cube.style.animation = "none";
window.addEventListener("mousemove", function (e) {
const xRatio = e.clientX / window.innerWidth;
const yRatio = e.clientY / window.innerHeight;
const rotY = (xRatio - 0.5) * 180;
const rotX = (0.5 - yRatio) * 90;
cube.style.transform = `rotateX(${
rotX - 20
}deg) rotateY(${rotY}deg)`;
});
window.addEventListener(
"touchmove",
function (e) {
if (!e.touches || !e.touches[0]) return;
const xRatio = e.touches[0].clientX / window.innerWidth;
const yRatio = e.touches[0].clientY / window.innerHeight;
const rotY = (xRatio - 0.5) * 180;
const rotX = (0.5 - yRatio) * 90;
cube.style.transform = `rotateX(${
rotX - 20
}deg) rotateY(${rotY}deg)`;
},
{ passive: false }
);
}
const cubeBtn = document.getElementById("cube-toggle-btn");
const cubeMenu = document.getElementById("cube-menu");
if (cubeBtn && cubeMenu) {
cubeBtn.addEventListener("click", function (e) {
e.stopPropagation();
if (
cubeMenu.style.display === "none" ||
cubeMenu.style.display === ""
) {
cubeMenu.style.display = "flex";
} else {
cubeMenu.style.display = "none";
}
});
window.addEventListener("click", function (e) {
if (cubeMenu.style.display === "flex") {
cubeMenu.style.display = "none";
}
});
cubeMenu.addEventListener("click", function (e) {
e.stopPropagation();
});
}
} catch (err) {
console.error("Button event error:", err);
}
});
document.getElementById("yearNow").textContent = new Date().getFullYear();