1

I have this element on my site, it's working fine but only set to a time delay and I'd like the counter to start when the element is in view, so when a customer scrolls to this element

enter image description here

Can anyone help update the code so the numbers start when the element is visible on the screen? I ideally need a copy and paste of new code as I am not a developer.

HTML

<div id="odometer" class="odometer">1</div>
<div id="odometer2" class="odometer">1</div>
<div id="odometer3" class="odometer">1</div>

JS

<script src="https://github.hubspot.com/odometer/odometer.js"></script>
<script>
  setTimeout(function() {
    odometer.innerHTML = 351;
  }, 3000);
  setTimeout(function() {
    odometer2.innerHTML = 3684;
  }, 4500);
  setTimeout(function() {
    odometer3.innerHTML = 110520;
  }, 5500);
</script>
  • 5
    Possible duplicate of [How to tell if a DOM element is visible in the current viewport?](https://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport) – cb64 Feb 22 '19 at 17:45
  • Close, but I need a copy and paste of new code to get this working as detailed. – Matt Matson Feb 23 '19 at 08:37
  • What do you mean a copy and paste of new code? – cb64 Feb 24 '19 at 00:04

0 Answers0