Amazon Product Scroll Bar Slider: HTML CSS Java Script
HTML Code
<!-- -------------------- HTML -------------------- -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Amazon Product Scroll</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="products">
<img src="https://source.unsplash.com/400x400/?product,one" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,two" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,three" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,four" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,five" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,six" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,seven" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,eight" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,nine" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,ten" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,class" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,bed" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,toy" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,watch" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,ball" alt="product image">
<img src="https://source.unsplash.com/400x400/?product,pen" alt="product image">
</div>
<div class="arrow prev">
<img src="https://img.icons8.com/ios-filled/50/back.png" alt="prev">
</div>
<div class="arrow next">
<img src="https://img.icons8.com/ios-filled/50/forward--v1.png" alt="next">
</div>
</div>
<script src="main.js"></script>
</body>
</html>
CSS Code
/*-------------------- CSS --------------------*/
/* style.css */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
min-height: 100vh;
margin-top: 200px;
background-color: steelblue;
}
.container{
display: flex;
background-color: white;
padding: 30px 10px;
position: relative;
}
.products{
display: flex;
height: 200px;
overflow: scroll;
overflow-y: hidden;
}
.products img{
padding-bottom: 10px;
margin: 0 10px ;
height: 100%;
cursor: pointer;
}
.arrow{
position: absolute;
background-color: rgba(255, 255, 255, 0.461);
height: 100px;
width: 50px;
display: none;
align-items: center;
justify-content: center;
margin-top: 40px;
}
.container:hover .arrow{
display: flex;
}
.arrow:hover{
border: 3px solid #3e8bff;
}
.prev{
left: 0;
}
.next{
right: 0;
}
.arrow img{
width: 40px;
}
.products::-webkit-scrollbar{
height: 7px;
}
.products::-webkit-scrollbar-thumb{
background-color: #fff;
border-radius: 8px;
}
.container:hover .products::-webkit-scrollbar-thumb{
background-color: rgb(179, 179, 179);
}
Java Script Code
//-------------------- Java Script --------------------//
// main.js
let product = document.querySelector(".products")
let prev = document.querySelector(".prev")
let next = document.querySelector(".next")
let scrollStep= 800;
let scrollSpeed = 300;
prev.addEventListener("click", ()=>{
product.scrollBy({
left: -scrollStep,
behavior: "smooth"
})
})
next.addEventListener("click", ()=>{
product.scrollBy({
left: scrollStep,
behavior: "smooth"
})
})
0 Comments