JSFiddle - React, Tailwind, and code Playground
by Plippie Plop
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="portfolio_content container-fluid h-100">
<div class="row h-100 flex-row flex-nowrap scrollx long_content">
<div class="col-12 h-100 project d-table" id="project1">
<div class="project_title d-table-cell align-middle">
<p>
Project 1
</p>
</div>
</div>
<div class="col-12 h-100 project d-table" id="project2">
<div class="project_title d-table-cell align-middle">
<p>
Project 2
</p>
</div>
</div>
<div class="col-12 h-100 project d-table" id="project3">
<div class="project_title d-table-cell align-middle">
<p>
Project 3
</p>
</div>
</div>
<div class="col-12 h-100 project d-table" id="project4">
<div class="project_title d-table-cell align-middle">
<p>
Project 4
</p>
</div>
</div>
</div>
</div>
CSS
html, body {
height: 100%;
overflow:hidden;
}
.portfolio_content .scrollx {
overflow-x: scroll;
}
.portfolio_content .long_content {
overscroll-behavior-inline: contain;
scroll-behavior: smooth;
scroll-snap-type: x mandatory;
}
.portfolio_content .project {
scroll-snap-align: center;
scroll-snap-stop: always;
}
.portfolio_content .project_title {
display: block;
margin: auto;
text-align: center;
}
.portfolio_content .project_title h1 {
font-size: 96px;
line-height: 0.8;
}
#project1, #project3 {
background-color: #EEE;
}
#project2, #project4 {
background-color: #CCC;
}
JavaScript
// 'swipe' left or right with mouse wheel:
const container = document.querySelector('.long_content');
container.addEventListener('wheel', (evt) => {
evt.preventDefault();
//scroll deirection
let delta = evt.deltaY;
//take widht of container:
let contWidth = evt.target.offsetWidth;
// check direction and apply to contWidth
if(delta < 0){
contWidth = -contWidth;
}
container.scrollLeft += contWidth;
});