Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
can I update a variable by making its value an function which gets an external value every 10 milliseconds with setInterval?

Can I update a variable by making its value a function that gets an external value every 10 milliseconds with setInterval? I'm a beginner so be kind.

var scrollTop = setInterval(function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
}, 10);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

These are some of the observations and suggestions to improve your code,hope this will help you.

  • Set Interval will return an interval ID which means your var scrollTop will have an id value like(0,1,2,4) instead of an offset value.

  • set Interval will take a callback function means just define your function outside of the interval and use that. it will make your code cleaner and easy to debug.

also you are beginner so you can read about this terms to understand it better callback functions, setInterval, arrow function(()=>)

function offSetValue(){
     var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : 
    (document.documentElement || document.body.parentNode || 
     document.body).scrollTop;
}

setInterval(() => offSetValue(), 10);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda