Scroll · 23 of 34
Horizontal Scroll
A row of items slides horizontally into view as you scroll vertically. A translateX driven by IntersectionObserver, without hijacking the wheel.
<section class="horizontal-scroll-section">
<div class="horizontal-track">
<div class="h-item">Item 1</div>
<div class="h-item">Item 2</div>
<div class="h-item">Item 3</div>
<div class="h-item">Item 4</div>
</div>
</section>
.horizontal-scroll-section {
min-height: 35vh;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
color: #f0f0f5;
}
.horizontal-track {
display: flex;
gap: 1rem;
opacity: 0;
transform: translateX(100px);
transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1), opacity 1s;
}
.h-item {
width: 120px;
height: 120px;
background: #12121a;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
.horizontal-scroll-section.in-view .horizontal-track {
opacity: 1;
transform: translateX(0);
}
var section = document.querySelector('.horizontal-scroll-section');
new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
entry.target.classList.toggle('in-view', entry.isIntersecting);
});
}, { threshold: 0.25 }).observe(section);