-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
175 lines (124 loc) · 4.34 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// start navbar shadow
window.onscroll = function() {
const navbar = document.getElementById("buttonBox")
if (window.pageYOffset > 0) {
navbar.classList.add("headerBoxShadow");
} else {
navbar.classList.remove("headerBoxShadow");
}
};
// end navbar shadow
// beginning of star script
var ctx = cnv.getContext("2d");
var W = window.innerWidth;
var H = window.innerHeight;
cnv.width = W;
cnv.height = H;
ctx.fillStyle = "#242936";
ctx.fillRect(0, 0, W, H);
ctx.shadowBlur = 10;
ctx.shadowColor = "white";
let starCount = 0;
const maxStars = 100;
function starsAnimation() {
if (starCount <= maxStars) {
let x = W * Math.random();
let y = H * Math.random();
let r = 2.5 * Math.random();
let factor = (y / H) * 0.2 + 0.8;
if (Math.random() > factor) {
ctx.beginPath();
ctx.fillStyle = "#AAB5A9";
ctx.arc(x, y, r, 0, Math.PI * 2);
ctx.fill();
starCount ++;
}
setTimeout(starsAnimation, 90);
}
}
starsAnimation();
// ending of star script
// beginning of code arrow project
function setupDropdown(button, dropdown) {
let toggleIndex = 0;
button.addEventListener('click', () => {
if (toggleIndex === 0) {
dropdown.style.backgroundColor = "grey";
dropdown.style.height = dropdown.scrollHeight + "px";
toggleIndex++;
} else {
dropdown.style.backgroundColor = "transparent";
dropdown.style.height = button.scrollHeight + "px";
toggleIndex--;
}
});
document.addEventListener('click', (event) => {
if (!dropdown.contains(event.target)) {
dropdown.style.backgroundColor = "transparent";
dropdown.style.height = button.scrollHeight + "px";
toggleIndex = 0;
}
});
}
const btnDropLth = document.querySelector(".bloc-top-lth");
const dropdownlth = document.querySelector(".dropdownLth");
setupDropdown(btnDropLth, dropdownlth);
const btnDropAkb = document.querySelector(".bloc-top-akb");
const dropdownakb = document.querySelector(".dropdownAkb");
setupDropdown(btnDropAkb, dropdownakb);
const btnDropJarod = document.querySelector(".bloc-top-jarod");
const dropdownjarod = document.querySelector(".dropdownJarod");
setupDropdown(btnDropJarod, dropdownjarod);
const btnDropBlogAI = document.querySelector(".bloc-top-BlogAIPro");
const dropdownBlogAI = document.querySelector(".dropdownBlogAIPro");
setupDropdown(btnDropBlogAI, dropdownBlogAI);
// ending of arrow code project
// beginning of BrBad bear buoyancy
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateRandomKeyframes() {
const keyframes = [
{ percent: 0, x: 0, y: 0 },
{ percent: 25, x: getRandomInt(-20, 20), y: getRandomInt(-20, 20) },
{ percent: 50, x: getRandomInt(-20, 20), y: getRandomInt(-20, 20) },
{ percent: 75, x: getRandomInt(-20, 20), y: getRandomInt(-20, 20) },
{ percent: 100, x: 0, y: 0 }
];
let keyframesCSS = '@keyframes floatDiagonal {';
keyframes.forEach(frame => {
keyframesCSS += `
${frame.percent}% {
transform: translate(-50%, -50%) translate(${frame.x}px, ${frame.y}px);
}
`;
});
keyframesCSS += '}';
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = keyframesCSS;
document.head.appendChild(styleSheet);
}
document.addEventListener('DOMContentLoaded', () => {
generateRandomKeyframes();
adjustFloatingImagePosition();
});
window.addEventListener('resize', adjustFloatingImagePosition);
function adjustFloatingImagePosition() {
const projectBox = document.querySelector('.projectBox');
const floatingImage = document.getElementById('floatingImage');
const projectBoxRect = projectBox.getBoundingClientRect();
floatingImage.style.left = `${projectBoxRect.right + 90}px`;
floatingImage.style.animation = 'floatDiagonal 12s ease-in-out infinite';
}
// ending of BrBad bear buoyancy
// début code bouton du bas
const btn = document.querySelector('.retourHaut');
btn.addEventListener('click', () => {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
})
})
// fin code bouton du bas