An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
November 16, 2021 08:45 pm GMT
Original Link: https://dev.to/ljnce/horizontal-scroll-on-mouse-wheel-nothing-easier-mfm
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:
HTML
<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>
.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;}
JS
$('.horizonal-wrapper').on('wheel', function(e){ e.preventDefault(); $(this).scrollLeft($(this).scrollLeft() + e.originalEvent.deltaY);});
This is my fiddle example:
https://jsfiddle.net/k0bojwhu/
Thank you and good coding!
Original Link: https://dev.to/ljnce/horizontal-scroll-on-mouse-wheel-nothing-easier-mfm
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To