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

145
Views
Image sequence animation on scroll when element is reached

I'm trying to implement an animation that switches images on scroll when it's wrapping div scrolls into the viewport. My problem is that the animation starts as soon as someone starts scrolling, so the animation is already at the end when #wrapper comes into viewport.

How to achieve that the animation starts when #wrapper scrolls into the viewport?

Unfortunately my JS/jQuery knowledge is very poor but this is what I got til now:

JSFiddle

HTML:

<div class="page_content_before_image_animation">
  <p>lorem ipsum …</p>
    </div>
      <div id="load" data-images="19"></div>
        <div id="wrapper">
          <img class="sequenzbilder" src="https://twdp.de/sequence/1.jpg" width="600" height="661" />
        </div>

JS:

var images = [];
    for (i = 1; i <= $('#load').attr('data-images'); i++) {
      images.push('https://twdp.de/sequence/' + i + '.jpg');
    }
    
    $(images).each(function() {
      $('<img class="sequenzbilder" />')[0].src = this;
    });
    
    
    var totalImages = images.length;
    
    var pageHeight = $(document).height() - $(window).height();
    var scrollInterval = Math.floor(pageHeight / 140);
    
    var viewport = $(window),
      slowdown;
    viewport.on('scroll', function() {
      i = Math.floor($(this).scrollTop() / scrollInterval);
      $('.sequenzbilder').attr('src', images[i]);
      slowdown = Math.ceil(viewport.scrollTop() / 20);
    });
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!