jeudi 23 juillet 2020

How do I make sure the function doesn't run more than once?

so I'm trying to make it so that when a user scrolls down far enough on my website, a function with a typewriter effect will kick in.

<script>
function typeWriter() {
  if (i < txt.length) {
    document.getElementById("tbag").innerHTML += txt.charAt(i);
    i++;
    setTimeout(typeWriter, speed);
  }
}
</script>
<script>


$(document).ready(function(){
  $(document).scroll(function(){
    var scrolled = $(this).scrollTop()

    if (scrolled >1200){
      typeWriter()


    }
  })

})


</script>

Any help will be appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire