I attempted to build a horizontal page layout - my first one. I built it to work with scrolling up and down.
See here:
$(function() {
var lastPos = 0;
$(window).scroll(function() {
var currPos = $(document).scrollLeft();
if (lastPos < currPos) {
console.log('scroll right');
}
if (lastPos > currPos)
{
console.log('scroll left');
}
lastPos = currPos;
});
});
.scroll_outer-wrapper {
width: 100vh;
height: 100vw;
transform: rotate(-90deg) translateX(-100vh);
transform-origin: top left;
/* I have to comment these two lines in order for the left and right scroll to work
HOWEVER, the up and down scroll won't work.
If I uncommend these two lines, the up and down scroll will work as expected, but the left and right scroll won't work anymore.
*/
overflow-y: scroll;
overflow-x: hidden;
position: absolute;
}
.scroll_wrapper {
display: flex;
flex-direction: row;
width: 400vw;
transform: rotate(90deg) translateY(-100vh);
transform-origin: top left;
transition: transform 0.5s ease;
}
.scroll_section {
width: 100vw;
height: 100vh;
}
.scroll_section.one {
background: black;
color: white;
}
.scroll_section.two {
background: white;
color: black;
}
.scroll_section.three {
background: black;
color: white;
}
.scroll_section.four {
background: pink;
color: black;
}
#scrollBtn {
position: absolute;
bottom: 20px;
right: 20px;
background-color: darkblue;
color: white;
border: none;
width: 80px;
height: 80px;
border-radius: 50%;
text-transform: uppercase;
font-size: 12px;
line-height: 20px;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="scroll_outer-wrapper">
<div class="scroll_wrapper">
<section class="scroll_section one"><h2>section 1</h2></section>
<section class="scroll_section two"><h2>section 2</h2></section>
<section class="scroll_section three"><h2>section 3</h2></section>
<section class="scroll_section four"><h2>section 4</h2></section>
</div>
</div>
What I didn't take into consideration, and it was a newbie mistake, was that I might have to also add the feature of scrolling from left to right as well as being able to scroll from top to bottom.
Right now I'm pretty advanced with the project and changing the whole structure would be really troublesome, so I come to you with my last hope to salvage this project structure while also implementing this feature...
TLDR; How to make a left to right & top to bottom scroll behave the same way (horizontal scroll) ?
Here is my code example.