I'm trying to create a simple slider with 3 sections, each section has some texts, first, I started to create animations for the paragraphs of the section-a it works, but what I want is to create a slider(carousel) that is going to display the first section-a then section-b then section-c and we back to section-a and so on. I tried for many hours but I got stuck What do you think?
window.addEventListener('load', ()=> {
const textEL = document.getElementsByClassName("text");
const showOne = document.getElementById("show-one");
const showTwo = document.getElementById("show-two");
const showTree = document.getElementById("show-tree");
delay = 500;
const animation = ()=> {
setTimeout(()=> {
textEL[0].style.transform = "translate(0%)"
}, delay)
setTimeout(()=> {
textEL[1].style.transform = "translate(0%)"
}, delay * 2)
setTimeout(()=> {
textEL[2].style.transform = "translate(0%)"
}, delay * 3)
setTimeout(()=> {
textEL[3].style.transform = "translate(0%)"
}, delay * 4)
setTimeout(()=> {
showOne.style.opacity = "0"
}, delay * 5)
}
animation();
// setInterval(animation, delay *6);
});
@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;1,100;1,200;1,300;1,400&display=swap");
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
margin: 0;
background: #555;
display: flex;
justify-content: center;
align-items: center;
}
.section-a {
height: 100px;
width: 90%;
transition: 1.7s ease;
margin: auto;
position: relative;
transform: translateX(0);
}
.text {
color: #000000;
margin: auto;
font-size: 1.5rem;
/*Animation*/
transition: all 0.75s ease;
text-transform: uppercase;
letter-spacing: 5px;
font-weight: 800;
text-align: center;
transform: translateX(120%);
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<script src="./script.js" defer></script>
<title>Real Slider</title>
</head>
<body>
<div class="section-a" id="show-one" >
<p class="text"> Knowledge is Power</p>
<p class="text"> Power is Knowledge </p>
<p class="text"> Get Educated </p>
<p class="text"> Stay Positive </p>
</div>
<!-- <div class="section-b" id="show-two">
<p class="text"> Coding is a game</p>
<p class="text"> Ride slow </p>
<p class="text"> Get Educated </p>
<p class="text"> Now or Never </p>
</div>
<div class="section-c" id="show-tree">
<p class="text"> Summer</p>
<p class="text"> Power is Knowledge </p>
<p class="text"> Get Educated </p>
<p class="text"> Stay Positive </p>
</div> -->
</body>
</html>