You need to specify the target element and id, and then get its postulation on top var pos = document.getElementById('targetId').scrollHeight - element.clientHeight; and compare it with the window.pageYOffset height of window.pageYOffset .
If the widow's offset is greater than pos, you can start the counter. You must bind the comparison to the window.onscroll event.
You should also remember in the variable if you started the counter so that the element no longer starts it twice.
source share