Demande d'aide

Par Arcamon, il y a 2 ans


Bonjour, je cherche à faire un slider automatique pour un site WEB, mais j'ai 2 problèmes :

Pourriez-vous m'aider ? Voici mes différents codes :

HTML :

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Freelance - GreatJob!</title> <link rel="shortcut icon" href="images/Logo_Miniature_GreatJob!.png"> <link rel="stylesheet" href="test.css"> </head> <body> <main> <div class="slideshow-container"> <div class="mySlides slide"> <img src="images/img1.png" style="width:100%"> <button onclick="window.location='JoinUS.html'" class="choix"> Je postule</button> </div> <div class="mySlides slide"> <img src="images/Img2.png" style="width:100%"> </div> <div class="mySlides slide"> <img src="images/Img3.png" style="width:100%"> <button onclick="window.location.href='https://x.com/KilfenBaridon';" class="choix"> Je partage </button> </div> <a class="prev" onclick="plusSlides(-1)">❮</a> <a class="next" onclick="plusSlides(1)">❯</a> <div style="text-align:center"> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> </div> </div> <script src="test.js"></script> </body> </html>

CSS :

* { background-color: rgb(20, 27, 51); color: white; font-family: sans-serif; margin: 5px; } header { text-align: center; } main { box-sizing: border-box; } .slideshow-container { max-width: 1700px; position: relative; margin: auto; overflow: hidden; } .prev, .next { cursor: pointer; position: absolute; top: 50%; width: auto; padding: 16px; margin-top: -22px; color: white; font-weight: bold; font-size: 18px; transition: 0.6s ease; border-radius: 0 3px 3px 0; user-select: none; } .next { right: 0; border-radius: 3px 0 0 3px; } .prev:hover, .next:hover { color: #4A86E8; } .choix { cursor: pointer; position: absolute; width: 150px; height: 30px; color: white; font-weight: bold; font-size: 18px; display: block; border: 2px solid antiquewhite; border-radius: 19px; margin: auto; transition: all 0.5s; background-color: #4A86E8; bottom: 35%; right: 30%; } .choix:hover { box-shadow: 1px 1px 4px antiquewhite; transform: scale(1.1, 1.1) } .dot { height: 12px; width: 12px; background-color: grey; border-radius: 50%; bottom: 30px; position: relative; display: inline-block; transition: background-color 0.6s ease; } .active { background-color: #4A86E8; } .slide { animation-name: slide; animation-duration: 2s; } @keyframes slide { from { transform : translateX(750px); } to { transform: translateX(0px); } }

JS :

let slideIndex = 1; let slideTimer; showSlides(); function plusSlides(n) { clearInterval(slideTimer); // Réinitialiser le timer slideIndex += n; showSlides(); } function currentSlide(n) { clearInterval(slideTimer); // Réinitialiser le timer slideIndex -= n; showSlides(); } function showSlides() { let i; let slides = document.getElementsByClassName("mySlides"); let dots = document.getElementsByClassName("dot"); if (slideIndex > slides.length) { slideIndex = 1; } if (slideIndex < 1) { slideIndex = slides.length; } for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; // Définir le nouveau timer après chaque changement de diapositive slideTimer = setTimeout(function() { slideIndex++; showSlides(); }, 6000); }

Merci d'avance !

2 réponses

Arcamon, il y a 2 ans

J'ai peut etre quelques parties du CSS qui ne servent à rien (passé malgres mon check), n'y faites pas gaffe

gena, il y a 2 ans

bonjour, concerant le bouton je te laisse le code ci-desous, pas besoin de lui mettre une classe juste de l'appeler tel quel, tu peut biensur jouer avec l'axe afin de le baisser ou de le remonter:

button {
cursor: pointer;
margin: auto;
width: 150px;
height: 30px;
color: white;
font-weight: bold;
font-size: 18px;
display: block;
border: 2px solid antiquewhite;
border-radius: 19px;
margin: auto;
transition: all 0.5s;
background-color: #4A86E8;
/ ------------------------------------ /
position: absolute;
top: 50%;
left: 50%;
/ Obliger pour recentrer le point au milieu de ton bouton et non en prenant en compte la position à partir du bord /
transform: translate(-50%, -50%);
/ ------------------------------------ /

}

button:hover {
box-shadow: 1px 1px 4px antiquewhite;
transform: scale(1.1, 1.1)
}