1

I'm making a one page website which has two sections. I've added typewriter effect(something like this- codepen.io/danielgroen/pen/VeRPOq ) to the second section of the website. However, this effect starts once the page is loaded. How to start the effect only when I scroll to the second section?

<section>
 <div> 
   <p> hi how are you? </p>
 </div>
</section>
<section>
<h1> Hallo, Wij zijn Occhio! </h1>
</section>
1
  • Listen to the document scroll event and check the position of your section Commented Jun 28, 2017 at 10:40

1 Answer 1

1

You can run your effect when you scroll the window and when you reach the second section

$(window).scroll(function() { 

      if ($(window).scrollTop() >  $("section:nth-of-type(2)").offset().top) {
             // run your effect here
      }

});
Sign up to request clarification or add additional context in comments.

5 Comments

codepen.io/anon/pen/YQYGBN Like this? Sorry I'm a noob
@nafri i don't understand the question?
I added the above lines to the code but the animation stops working codepen.io/anon/pen/YQYGBN
@nafri look at this codepen.io/anon/pen/eRygbV.. scroll to the second section to see the effect
Thanks! But after the word 'amsterdam', the animation starts shivering due to some glitch

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.