EDIT On closer inspection this is pretty broken when resizing the viewport. It stops working or on narrow windows and the scroll is super super fast. So I'm putting it up for bounty!
--
I've seen something similar and have been trying to refactor the JS. I have two columns of content, which when scrolled move in opposite directions. This should loop continuously.
The issue is if I remove the height from the .project
element. The content will scroll smoothly when scrolling down but not up. The height/length of content will vary so I can't really have a fixed value here.
This seems to depends on viewport height. If the UI behaves as intended and I reduce the width of the viewport it can stop working like described above. But if I then reduce the height - it can begin to behave correctly again. So maybe it's down to how much content is visible in the viewport on load?
Example (also in code snippet): https://jsfiddle.net/rdowb0y5/1
I will add a 'media query' so that this is only visible on tablet/desktop views and on mobile devices the JS is removed and the content just stacked.
Thanks in advance - really looking forward to some support on this!
$(document).ready(function() {
var num_children=$('.split-loop__left').children().length;
var child_height=$('.split-loop__right').height() / num_children;
var half_way=num_children * child_height / 2;
$(window).scrollTop(half_way);
function crisscross() {
var parent=$(".split-loop"); //.first();
var clone=$(parent).clone();
var leftSide=$(clone).find('.split-loop__left');
var rightSide=$(clone).find('.split-loop__right');
if (window.scrollY > half_way) {
//We are scrolling up
$(window).scrollTop(half_way - child_height);
var firstLeft=$(leftSide).children().first();
var lastRight=$(rightSide).children().last();
lastRight.appendTo(leftSide);
firstLeft.prependTo(rightSide);
}
else if (window.scrollY < half_way - child_height) {
var lastLeft=$(leftSide).children().last();
var firstRight=$(rightSide).children().first();
$(window).scrollTop(half_way);
lastLeft.appendTo(rightSide);
firstRight.prependTo(leftSide);
}
$(leftSide).css('bottom', '-'+ window.scrollY + 'px');
$(rightSide).css('bottom', '-'+ window.scrollY + 'px');
$(parent).replaceWith(clone);
}
$(window).scroll(crisscross);
}
);
/* Hide Scroll Bars */
::-webkit-scrollbar {
display: none;
}
html,
body {
margin: 0;
padding: 0;
-ms-overflow-style: none;
/* IE and Edge */
scrollbar-width: none;
/* Firefox */
}
/* Basic Styling */
img {
border: 1px solid black;
margin-bottom: 24px;
width: 100%;
max-width: 100%;
}
h2 {
font-size: 14px;
font-weight: normal;
margin-bottom: 4px;
font-family: 'Inter', sans-serif;
}
p {
color: black;
font-size: 11px;
font-family: 'Inter', sans-serif;
}
/* Content will be in these eventually */
.bar-left,
.bar-right {
border-right: 1px solid black;
box-sizing: border-box;
height: 100vh;
position: fixed;
top: 0;
left: 0;
width: 48px;
z-index: 10000;
}
.bar-right {
border: none;
border-left: 1px solid black;
left: auto;
right: 0;
}
/* Split Loop */
.split-loop {
position: relative;
margin: 0 48px;
}
.split-loop__left {
// position: absolute;
// left: 0%;
// top: 0%;
// right: auto;
// bottom: auto;
// z-index: 4;
width: 50%;
}
.split-loop__right {
border-left: 1px solid black;
box-sizing: border-box;
position: fixed;
right: 48px;
bottom: 0;
z-index: 5;
width: calc(50% - 48px);
}
.project {
box-sizing: border-box;
border-bottom: 1px solid black;
height: 600px;
padding: 48px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<header class="bar-left">
</header>
<div class="bar-right">
</div>
<div class="view">
<div class="grid split-loop">
<div class="split-loop__left">
<div class="grid__item project">
<img src="https://www.fillmurray.com/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
<div class="grid__item project">
<img src="https://www.fillmurray.com/g/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
<div class="grid__item project">
<img src="https://www.fillmurray.com/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
</div>
<div class="split-loop__right">
<div class="grid__item project">
<img src="https://www.fillmurray.com/g/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
<div class="grid__item project">
<img src="https://www.fillmurray.com/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
<div class="grid__item project">
<img src="https://www.fillmurray.com/g/600/400" alt="" class="project__media" />
<h2 class="project__title">Project Title</h2>
<p class="project__desc">Short Description</p>
</div>
</div>
</div>
</div>