Bien sûr ! Voici un exemple simple d’application web qui affiche un diaporama de photos, en utilisant React (pour l’interface) et un peu de CSS pour le style.
Tu pourras l’adapter facilement à tes besoins.
1. Crée le projet React
Si tu n’as pas encore créé de projet React, fais-le avec :
npx create-react-app diaporama
cd diaporama
2. Remplace le contenu de src/App.js par :
import React, { useState, useEffect } from "react";
import "./App.css";
const photos = [
"https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=800&q=80",
"https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=crop&w=800&q=80",
"https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=crop&w=800&q=80",
"https://images.unsplash.com/photo-1500534314209-a25ddb2bd429?auto=format&fit=crop&w=800&q=80"
];
function App() {
const [index, setIndex] = useState(0);
useEffect(() => {
const timer = setInterval(() => {
setIndex((prev) => (prev + 1) % photos.length);
}, 3000); // Change d'image toutes les 3 secondes
return () => clearInterval(timer);
}, []);
const prevPhoto = () => setIndex((index - 1 + photos.length) % photos.length);
const nextPhoto = () => setIndex((index + 1) % photos.length);
return (
<div className="diaporama-container">
<h1>Diaporama de Photos</h1>
<div className="photo-wrapper">
<img src={photos[index]} alt={`Diapo ${index + 1}`} />
</div>
<div className="controls">
<button onClick={prevPhoto}>Précédent</button>
<span>
{index + 1} / {photos.length}
</span>
<button onClick={nextPhoto}>Suivant</button>
</div>
</div>
);
}
export default App;
3. Ajoute un peu de style dans src/App.css :
.diaporama-container {
text-align: center;
margin-top: 40px;
font-family: Arial, sans-serif;
}
.photo-wrapper {
width: 600px;
height: 400px;
margin: 0 auto 20px auto;
overflow: hidden;
border-radius: 12px;
box-shadow: 0 4px 16px rgba(0,0,0,0.2);
background: #eee;
display: flex;
align-items: center;
justify-content: center;
}
.photo-wrapper img {
width: 100%;
height: 100%;
object-fit: cover;
transition: opacity 0.5s;
}
.controls {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
}
button {
padding: 8px 20px;
font-size: 16px;
border: none;
border-radius: 6px;
background: #1976d2;
color: white;
cursor: pointer;
transition: background 0.2s;
}
button:hover {
background: #1565c0;
}
4. Lance l’application
npm start
Voilà !
Tu as un diaporama de photos simple, avec changement automatique et boutons pour naviguer.
Tu peux remplacer les URLs dans le tableau photos par tes propres images.
Si tu veux une version sans React (juste HTML/JS/CSS), dis-le-moi !