I’m trying to make an Instagram story, but I’m having trouble even though everything is correct in javascript, can you help?
HTML
<!DOCTYPE html>
<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">
<title>HTML</title>
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
</head>
<body>
<div class="container">
<div class="horizontal-scroll">
<button class="btn-scroll" id="btn-scroll-left" onclick="scrollHorizontally(1)" ><i class="fas fa-chevron-left"></i></button>
<button class="btn-scroll" id="btn-scroll-right" onclick="scrollHorizontally(-1)" ><i class="fas fa-chevron-right"></i></button>
<div class="storys-container">
<div class="story-circle"><img src="./img/face/1.jfif "></div>
<div class="story-circle"><img src="./img/face/2.jfif "></div>
<div class="story-circle"><img src="./img/face/3.jfif "></div>
<div class="story-circle"><img src="./img/face/4.jfif "></div>
<div class="story-circle"><img src="./img/face/5.jfif "></div>
<div class="story-circle"><img src="./img/face/6.jfif "></div>
<div class="story-circle"><img src="./img/face/7.jfif "></div>
<div class="story-circle"><img src="./img/face/8.jfif "></div>
<div class="story-circle"><img src="./img/face/9.jfif "></div>
</div>
</div>
</div>
<script src="./script.js"></script>
</body>
</html>
css
body{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container{
display: flex;
justify-content: center;
align-items: center;
background-color: #f9f9f9;
height: 100vh;
}
.horizontal-scroll{
width: 600px;
height: 80px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
position: relative;
overflow: hidden;
}
.horizontal-scroll .btn-scroll{
background-color: #fff;
color: #999;
box-shadow: 0 0 10px #999;
padding: 5px 8px;
border: 0;
border-radius: 50%;
margin: 0 5px;
z-index: 1;
cursor: pointer;
transition: 1s;
}
.storys-container{
display: flex;
flex-direction: row;;
justify-content: flex-start;
align-items: center;
position: absolute;
left: 0;
transition: 0.5s all ease-out;
}
.story-circle{
background: linear-gradient(rgb(231,0,231),rgb(255,115,0));
width: 60px;
height: 60px;
margin: 15px 10px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
}
.story-circle img{
width: 52px;
height: 52px;
border-radius: 50%;
border: 2px solid #fff;
}
javascript
let currentScroolPosition = 0;
let scroolAmount = 320;
const sCont = document.querySelector(".storys-container")
const hScroll = document.querySelector(".horizontal-scroll")
const btnScrollLeft = document.querySelector("#btn-scroll-left")
const btnScrollRight = document.querySelector("#btn-scroll-right")
btnScrollLeft.style.opacity = "0"
let maxScroll = -sCont.offsetWidth + hScroll.offsetWidth;
function scrollHorizontally(val){
currentScroolPosition += ( val * scrollAmount );
if(currentScroolPosition > 0){
currentScroolPosition = 0;
btnScrollLeft.style.opacity = "0"
}else{
btnScrollLeft.style.opacity = "1"
}
if(currentScroolPosition <= maxScroll){
currentScroolPosition = maxScroll;
btnScrollRight.style.opacity = "0"
}else{
btnScrollRight.style.opacity = "1"
}
sCont.style.left = currentScroolPosition + "px";
}
I’m waiting for your answers, I couldn’t solve this problem for hours
Here is the video of the friend who made it. everything is correct but it’s not working for me either.
https://www.youtube.com/watch?v=LFVFxDXQxxE&ab_channel=Fullstack4Dev