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

166
Vistas
Jquery reload every second while scrolled down in the beginning

I am trying to make a div reload every second and to have it scrolled down in the beginning. Right know I put both in the same function, because scrolling script doesn't work when they are apart (because of the reloading). However, in this case it scrolls down every second. Is there a way to have the div scrolled down only in the beginning and reload it every second? Thanks!

<script>
    function load(){
        $('#screen').load('includes/update.php');
        $("#screen").scrollTop($("#screen")[0].scrollHeight);
    }
    setInterval(function(){
        load();
    }, 1000);
</script>
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You could have an outher variable that says if you have scrolled or not :

<script>
    var scrolled = false;
    function load(){
        $('#screen').load('includes/update.php');
        if(!scrolled){                
            $("#screen").scrollTop($("#screen")[0].scrollHeight);
            scrolled = true;
        }
    }
    setInterval(function(){
        load();
    }, 1000);
</script>

This way, load will be called every second, but since scrolled is in the outer scope, it will be the same variable for each call.

over 4 years ago · Santiago Trujillo Denunciar

0

You have to use the complete callback function for .load() like this:

<script>
    function load(){
        $('#screen').load('includes/update.php', function(){
            $("#screen").scrollTop($("#screen")[0].scrollHeight);
        });
    }
    setInterval(function(){
        load();
    }, 1000);
</script>

And it means that when the content is loaded fully, then call the callback functions and scroll to the top.

For more reference you can use the jQuery .load() documentation

over 4 years ago · Santiago Trujillo 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