Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda