website/static/js/script.js
2025-05-15 10:55:25 +02:00

68 lines
2.1 KiB
JavaScript

// DARK MODE
document.addEventListener("DOMContentLoaded", function() {
const switchTheme = document.querySelector("#switch");
switchTheme.addEventListener("click", function () {
document.body.classList.toggle("dark-mode");
});
});
// CAROUSSEL
document.addEventListener("DOMContentLoaded", function () {
const track = document.querySelector('.carousel-track');
let index = 0;
function updateSlide() {
const slideWidth = document.querySelector('.carousel-slide').offsetWidth;
track.style.transform = `translateX(-${index * slideWidth}px)`;
}
setInterval(() => {
index = (index + 1) % document.querySelectorAll('.carousel-slide').length;
updateSlide();
}, 3000);
});
// BOUTON
document.addEventListener("DOMContentLoaded", function () {
const container = document.querySelector('.button-area');
const button = document.getElementById('trickyButton');
button.addEventListener('mouseenter', () => {
const maxX = container.clientWidth - button.offsetWidth;
const maxY = container.clientHeight - button.offsetHeight;
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * maxY);
button.style.left = `${randomX}px`;
button.style.top = `${randomY}px`;
});
});
// COMPTEUR
document.addEventListener("DOMContentLoaded", function () {
let compteur = 0;
document.getElementById("incrementer").addEventListener("click", () => {
compteur++;
document.getElementById("compteur").textContent = compteur;
});
});
// ADDITION
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("additionner").addEventListener("click", () => {
const a = parseFloat(document.getElementById('chiffre1').value);
const b = parseFloat(document.getElementById('chiffre2').value);
if (isNaN(a) || isNaN(b)) {
document.getElementById('resultat').textContent = "Entrée invalide";
} else {
const somme = a + b;
document.getElementById('resultat').textContent = somme;
document.getElementById('resultBox').style.display = "block";
}
});
});