Skip to content

Commit 305d2ff

Browse files
authored
Create ui.js
first commit
1 parent c4a3a5e commit 305d2ff

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

ui.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const langSelect = document.getElementById('langSelect');
3+
4+
langSelect.addEventListener('change', (event) => {
5+
const selectedLang = event.target.value;
6+
tran.setLang(selectedLang);
7+
});
8+
});
9+
10+
11+
var tran = new Translater({
12+
lang: "en"
13+
});
14+
15+
16+
const proModeButton = document.getElementById('proModeButton');
17+
const proModeElements = document.querySelectorAll('.promode');
18+
const proModeiElements = document.querySelectorAll('.promode-inline');
19+
showOrHide();
20+
21+
proModeButton.addEventListener('click', function() {
22+
showOrHide();
23+
});
24+
25+
26+
function showOrHide() {
27+
proModeElements.forEach(function(element) {
28+
if (element.style.opacity === '0') {
29+
element.style.opacity = '1';
30+
31+
} else {
32+
element.style.opacity = '0';
33+
34+
}
35+
});
36+
37+
38+
proModeiElements.forEach(function(element) {
39+
if (element.style.visibility === 'hidden') {
40+
element.style.visibility = 'visible';
41+
element.style.opacity = '0';
42+
setTimeout(function() {
43+
element.style.opacity = '1';
44+
}, 300);
45+
} else {
46+
element.style.opacity = '0';
47+
setTimeout(function() {
48+
element.style.visibility = 'hidden';
49+
}, 300);
50+
}
51+
});
52+
}
53+
54+
function isMobile() {
55+
const mobileThreshold = 1144;
56+
return window.innerWidth <= mobileThreshold;
57+
}
58+
59+
60+
//defilement aimanté
61+
if (!isMobile()) {
62+
document.addEventListener('DOMContentLoaded', () => {
63+
const container = document.getElementById('containerglobal');
64+
const sections = document.querySelectorAll('.section');
65+
66+
let isScrolling = false;
67+
const firstH1 = sections[0].querySelector('h1');
68+
if (firstH1) {
69+
firstH1.classList.add('visible');
70+
}
71+
container.addEventListener('scroll', () => {
72+
if (!isScrolling) {
73+
isScrolling = true;
74+
setTimeout(() => {
75+
snapScroll();
76+
isScrolling = false;
77+
}, 250);
78+
}
79+
});
80+
81+
function snapScroll() {
82+
const scrollPosition = container.scrollTop;
83+
let closestSection = sections[0];
84+
let minDistance = Math.abs(scrollPosition - closestSection.offsetTop);
85+
86+
sections.forEach(section => {
87+
const distance = Math.abs(scrollPosition - section.offsetTop);
88+
if (distance < minDistance) {
89+
minDistance = distance;
90+
closestSection = section;
91+
}
92+
});
93+
94+
container.scrollTo({
95+
top: closestSection.offsetTop,
96+
behavior: 'smooth'
97+
});
98+
sections.forEach(section => {
99+
const h1 = section.querySelector('h1');
100+
if (section === closestSection) {
101+
h1.classList.add('visible');
102+
} else {
103+
h1.classList.remove('visible');
104+
}
105+
});
106+
}
107+
});
108+
}
109+
110+
111+
//slider defi
112+
document.addEventListener('DOMContentLoaded', function() {
113+
const navItems = document.querySelectorAll('#definav h3');
114+
const slides = document.querySelectorAll('.sliderdefi .slide');
115+
116+
navItems.forEach((item, index) => {
117+
item.addEventListener('click', function() {
118+
slides.forEach(slide => slide.classList.remove('active'));
119+
slides[index].classList.add('active');
120+
});
121+
});
122+
123+
if (slides.length > 0) {
124+
slides[0].classList.add('active');
125+
}
126+
});

0 commit comments

Comments
 (0)