Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
Bi-Directional Infinite Scroll Loop

I'm currently using code from this question and this fiddle to achieve a bi-directional infinite scroll loop for a page of vertically scrolling images. This is working fine, however when the browser window is rescaled it breaks. How would I make it responsive? Also maybe there is a better way to approach this altogether now?

var bgHeight = 1970; // pixel height of background image

$(document).ready(function() {
  $('body').height(bgHeight + $(window).height());
  $(window).scroll(function() {
    if ($(window).scrollTop() >= ($('body').height() - $(window).height())) {
      $(window).scrollTop(1);
    } else if ($(window).scrollTop() == 0) {
      $(window).scrollTop($('body').height() - $(window).height() - 1);
    }
  });
});

$(window).resize(function() {
  $('body').height(bgHeight + $(window).height());
});
html,
body {
  height: 100%;
  overflow-x: none;
}

body {
  background-color: white;
  color: black;
  font-family: DecimaMono;
  font-size: 1rem;
  line-height: 1.85;
  height: 1970;
  width: 100vw;
  padding: 20px 20px;
  opacity: 100%;
  -moz-transition: all .15s ease-in;
  -o-transition: all .15s ease-in;
  -webkit-transition: all .15s ease-in;
  transition: all .15s ease-in;
}

img {
  max-width: 100%;
  max-height: 80vh;
  display: block;
  padding: 80px;
  background-color: #CCC; /* just for this demo */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="grid-3">
  <img src="assets/Clints/Clints-3.jpg" alt="" />
  <img src="assets/Clints/Clints-1.jpg" alt="" />
  <img src="assets/Clints/Clints-2.jpg" alt="" />
  <img src="assets/Clints/Clints-3.jpg" alt="" />
  <img src="assets/Clints/Clints-1.jpg" alt="" />
</div>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!