I have customized a parallax website template that is divided into various sections and slides. I want to incorporate a fixed image sequence on each slide that animates based on the scroll position. With 91 images in the animation sequence, it moves quickly. To slow it down, I would like to display a frame for every 4 or 5 pixels of scroll movement. How can I achieve this?
HTML:
<body>
<main>
<!-- SECTIONS -->
<section id="slide-1" class="homeSlideTall">
<div class="bcg" data-center="background-position: 50% 0px;" data-bottom-top="background-position: 50% 100px;" data-top-bottom="background-position: 50% -200px;" data-anchor-target="#slide-1">
<div class="hsContent" data-start="opacity: 1; top: 206px;" data-100-bottom="opacity: 1;top: 206px; left: 0px; width: 100%;" data-top-bottom="opacity: 0; top: -550" data-anchor-target="#slide-1">
<div class="boxScroll img" >
<img src="/img/model/0.png" width="960" height="540" />
</div>
<div class="boxScroll" >
<h2>Carried Away</h2>
Product-text
</div>
</div>
</div>
</section>
<section id="slide-3" class="homeSlideTall">
<div class="bcg" data-center="background-position: 50% 0px;" data-bottom-top="background-position: 50% 10px;" data-top-bottom="background-position: 50% -10px;" data-anchor-target="#slide-3">
<div class="hsContent" data-bottom-top="opacity: 0; top: 1000px" data-top="opacity: 1; top: 206px; width: 100%;" data-100-bottom="opacity: 1; position: fixed; top: 206px; width: 100%;" data-top-bottom="opacity: 0; top: -550" data-anchor-target="#slide-3">
<div class="boxScroll img" >
<img src="/img/model/0.png" width="960" height="540" />
</div>
<div class="boxScroll" >
<h2>Way</h2>
Product-text
</div>
</div>
</div>
</section>
</main>
</body>
JQuery:
jQuery(window).on("scroll",function() {
var n = $(window).scrollTop(),
divOffset = $('#slide-1').offset().top,
dist = (n - divOffset);
if (dist <= 0) { var dist = 0; } // Check that value isn't smaller than 0
if (dist >= 91) { var dist = 91; } // In case there aren't any more frames show the last one in the sequence
jQuery("#slide-1 .boxScroll img").attr({src:"/img/model/"+dist+".png"});
});