diff --git a/css/style.css b/css/style.css index c7a6c50..c0f2faf 100644 --- a/css/style.css +++ b/css/style.css @@ -12,6 +12,7 @@ display: flex; width: max-content; animation: scroll linear infinite; + will-change: transform; } .animate-ticker:hover { diff --git a/index.html b/index.html index a68e92c..21044c5 100644 --- a/index.html +++ b/index.html @@ -80,25 +80,74 @@ >
-
-
+
+ +
+ 🇫🇷 + CAC40 +
+ +
+
+
+ -
+
+ class="absolute left-0 top-0 h-full bg-slate-900 border-r border-slate-700/80 flex items-center px-4 space-x-3 z-20 shadow-lg" + style="width: 150px" + > + 🇪🇸 + IBEX35 +
+
+
+
+ -
+
+ class="absolute left-0 top-0 h-full bg-slate-900 border-r border-slate-700/80 flex items-center px-4 space-x-3 z-20 shadow-lg" + style="width: 150px" + > + 🇺🇸 + DOWJONES +
+
+
+
diff --git a/js/indices.js b/js/indices.js index e59fbb6..bdd9af3 100644 --- a/js/indices.js +++ b/js/indices.js @@ -2,13 +2,15 @@ let indicesData = []; function chargerDonnees() { + // Appel de l'API située dans le dossier php/ fetch("./php/api_indices.php") .then((response) => response.json()) .then((result) => { if (result.status === "success") { + // Stockage dans le tableau global JS indicesData = result.data; - // Mise à jour de l'affichage + // Mise à jour de tous les affichages afficherSyntheseCartes(); afficherTableauDetails(); alimenterBandeauxTicker(); @@ -29,9 +31,11 @@ function afficherSyntheseCartes() { const container = document.getElementById("cards-container"); container.innerHTML = ""; + // Trouver les indices uniques présents dans le tableau const indicesUniques = [...new Set(indicesData.map((item) => item.indice))]; indicesUniques.forEach((nomIndice) => { + // Récupère le premier élément (le plus récent) pour cet indice const dernier = indicesData.find((item) => item.indice === nomIndice); if (!dernier) return; @@ -88,7 +92,6 @@ function afficherTableauDetails() { } function alimenterBandeauxTicker() { - // Filtrer et trier par ordre alphabétique sur le champ 'nom' (ou 'indice' si 'nom' est vide) const preparerDonneesTicker = (nomIndice) => { let liste = indicesData.filter((item) => item.indice === nomIndice); @@ -109,43 +112,45 @@ function alimenterBandeauxTicker() { function remplirUnBandeau(elementId, donneesTriees) { const container = document.getElementById(elementId); - if (!container) return; + if (!container) { + console.error("Élément introuvable :", elementId); + return; + } if (donneesTriees.length === 0) { container.innerHTML = `Aucune donnée disponible`; return; } - let htmlContent = ""; + let blocs = ""; + donneesTriees.forEach((item) => { + const isPositive = parseFloat(item.variation_pct) >= 0; + const colorClass = isPositive ? "text-emerald-400" : "text-rose-400"; + const sign = isPositive ? "+" : ""; + const nomAffichage = item.nom || item.indice; + const coursFormate = parseFloat(item.cours).toLocaleString("fr-FR"); + const variationFormatee = parseFloat(item.variation_pct).toFixed(2); - // On génère une séquence d'éléments - const genererBlocs = () => { - let blocs = ""; - donneesTriees.forEach((item) => { - const isPositive = parseFloat(item.variation_pct) >= 0; - const colorClass = isPositive ? "text-emerald-400" : "text-rose-400"; - const sign = isPositive ? "+" : ""; - const nomAffichage = item.nom || item.indice; - const coursFormate = parseFloat(item.cours).toLocaleString("fr-FR"); - const variationFormatee = parseFloat(item.variation_pct).toFixed(2); + blocs += ` +
+ ${nomAffichage} + ${coursFormate} + ${sign}${variationFormatee}% +
+ `; + }); - blocs += ` -
- ${nomAffichage} - ${coursFormate} - ${sign}${variationFormatee}% -
- `; - }); - return blocs; - }; + // Duplication du contenu pour la boucle infinie fluide + container.innerHTML = blocs + blocs; - // On duplique le contenu pour assurer un effet de défilement infini fluide sans saccade - htmlContent = genererBlocs() + genererBlocs(); - container.innerHTML = htmlContent; + // Vitesse uniforme et lente + const dureeParElement = 6; + const dureeTotale = Math.max(30, donneesTriees.length * dureeParElement); + + container.style.animationDuration = `${dureeTotale}s`; } -// Lancer au chargement initial +// Lancer le chargement des données au démarrage de la page chargerDonnees(); // Rafraîchir automatiquement toutes les 60 secondes