Hello good people of stack overflow. Please I need assistance on how to apply a mousewheel feature to this horizontal list I made.
When I hover my mouse on the portion I expect other items (whose overflow is hidden) to show up - you know, just like a normal mousewheel scrolling - but this time, for a horizontal list like this...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mousewheel question</title>
<style>
div#main_container{
width: 100vw;
font-family: 'Maven Pro';
/*background-color: #8a5bcb;*/
}
#categories{
width: 100%;
display: flex;
justify-content: center;
}
#inner_categories{
width: 1200px;
display: flex;
/*flex-wrap: wrap;*/
white-space: nowrap;
overflow-y: hidden;
}
#inner_categories::-webkit-scrollbar{
height: 6px;
}
#inner_categories::-webkit-scrollbar-track{
background-color: transparent;
}
#inner_categories::-webkit-scrollbar-thumb{
background-color: #efefef;
border-radius: 10px;
}
#inner_categories::-webkit-scrollbar-thumb:hover{
background-color: #df00df;
}
.category{
font-size: 12px;
text-transform: capitalize;
background-color: #ef00ef;
padding: 2.5px 5px;
border-radius: 5px;
margin: 7px 0 9px 0;
}
.category:not(:last-child){
margin-right: 6px;
}
.category:hover{
cursor: pointer;
}
</style>
</head>
<body>
<div id="categories">
<div id="inner_categories">
<!-- ========== begin ========== CATEGORY TABS ========== begin ========== -->
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<div >
<span>grocery item</span>
</div>
<!-- ========== end ========== CATEGORY TABS ========== end ========== -->
</div>
</div>
</body>
</html>
CodePudding user response:
Add this to the bottom of your </body>
. In this case is inner_categories
the container.
<script>
var item = document.getElementById("inner_categories");
window.addEventListener("wheel", function (e) {
if (e.deltaY > 0) item.scrollLeft = 100;
else item.scrollLeft -= 100;
});
</script>