JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Horizontal Scroll on Vertical Mouse Scroll</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
.gallery {
display: flex;
overflow: hidden;
width: 100vw;
height: 100vh;
cursor: grab;
}
.gallery img {
width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="gallery">
<img src="https://img.freepik.com/free-photo/funny-monkey-with-glasses-studio_23-2150844104.jpg" alt="Image 1">
<img src="https://wallpapers.com/images/featured/funny-pictures-dzujtlgoq3utq7j4.jpg" alt="Image 2">
<img src="https://static.vecteezy.com/system/resources/thumbnails/031/693/879/small_2x/portrait-of-a-funny-pig-wearing-a-hat-and-sunglasses-on-a-black-background-ai-generative-photo.jpg" alt="Image 3">
<img src="https://via.placeholder.com/600x300" alt="Image 4">
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const gallery = document.querySelector('.gallery');
let isScrolling;
gallery.addEventListener('wheel', (e) => {
clearTimeout(isScrolling);
isScrolling = setTimeout(() => {
if (e.deltaY !== 0) {
// e.deltaY > 0 => scrolling down
// e.deltaY < 0 => scrolling up
gallery.scrollLeft += e.deltaY;
}
}, 6); // debouncing
});
});
</script>
</body>
</html>