0
I have this script:
var count = document.getElementById('contador').innerText;
var temp = count - 1000;
function counting() {
if(temp<count) {
setTimeout(function(){
document.getElementById('contador').innerText = temp;
temp=temp+10;
counting();
}, 30);
}else {
setTimeout(function(){
document.getElementById('contador').innerText = count;
}, 30);
}
}
/////////////////////////////////////
$(function(){
let run = false
let alturaContador = $('#contador').height()
let distanciaContadorDoTopo = $('#contador').offset().top
$(window).scroll(function(){
let posicaoScroll = $(window).scrollTop()
if (posicaoScroll >= (distanciaContadorDoTopo - (distanciaContadorDoTopo / 2)) && !run) {
run = true
alert('RODAR NÚMEROS')
counting();
}
});
});
That I am trying to get it to run only after the user sees (When the user scrolls up to the element) it, however unsuccessfully, someone has some suggestion?
Example: this site > convergenciasjc.com.br has these numbers (+ DE 552000 HOURS) "running" but usr does not see why they load with website.
<ul id="certificado">
<li class="conteudo_certificado">
<span class="titulo_number">+ de</span><span id="contador" class="titulo_number count">950</span>
<br>
<span class="titulo_certificado">toneladas coletadas</span>
</li>
</ul>
Edit the question and also put the HTML/CSS so that we can simulate its context. It will help you answer, it doesn’t need to be the html and css of the full page, but at least of this piece so that to test
– hugocsl
Be clearer, after "he sees". How do you know that he saw? does he perform any action when he "sees"?? What is the point of waiting for him to see? he clicks on some button signaling that he saw?
– Danielle Arruda torres
"only after the user sees it" he who? the way he wrote so the user has q see the script, and it doesn’t happen
– Ricardo Pontual