![](/style/images/good.png)
4
![](/style/images/bad.png)
Horizontal scroll on mouse wheel: nothing easier!
source link: https://dev.to/ljnce/horizontal-scroll-on-mouse-wheel-nothing-easier-mfm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
![Cover image for Horizontal scroll on mouse wheel: nothing easier!](https://res.cloudinary.com/practicaldev/image/fetch/s--qmbmXq1f--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5agssgfpb4n8mokpo60.png)
Luca
Posted on Nov 16
Horizontal scroll on mouse wheel: nothing easier!
Hi Dev! 🙋♂️
I've used this easy way for a horizontal scroll a lot and I want to share the code with you: ✌️
<div class="horizonal-wrapper">
<div class="horizonal-content">
<div class="content-1"></div>
<div class="content-2"></div>
<div class="content-3"></div>
</div>
</div>
Enter fullscreen modeExit fullscreen mode
.horizonal-wrapper {
height: 100vh;
width: 100%;
overflow-y: scroll;
}
.horizonal-content {
width: max-content;
}
.content-1,
.content-2,
.content-3 {
width: 50vw;
height: 100vh;
float: left;
border: 1px solid;
}
Enter fullscreen modeExit fullscreen mode
$('.horizonal-wrapper').on('wheel', function(e){
e.preventDefault();
$(this).scrollLeft($(this).scrollLeft() + e.originalEvent.deltaY);
});
Enter fullscreen modeExit fullscreen mode
This is my fiddle example:
https://jsfiddle.net/k0bojwhu/
Thank you and good coding! 🧑💻
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK