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

93
Vistas
Infinite Scroll pratice

I'm praticing the infinity sroll follow the source https://cs50.harvard.edu/web/2020/notes/6/ , but instead of calling to sever side, i just append elements form start to end index of datas array and the result as not as my expectation.I think that something related about Javascript's asynchronous feature. Is that true? How can I fix this problem?

<!DOCTYPE html>
<html>
    <head>
        <title>Infiniti Scroll</title>
    </head>
    <body>
        <div id="data"></div>
        <script>
            let start = 0
            let end = 100
            const datas = []
            for (let index = 0; index < 1000; index++) {
                datas.push(`<p>${index}</p>`);
            }
            document.addEventListener("DOMContentLoaded",function(){
                load();
                window.onscroll = ()=>
                {
                    
                    if (window.innerHeight + window.scrollY >= document.body.offsetHeight)
                    {
                        setTimeout(load,1000);
                        
                    }
                }
            });
            function load(){
                for (let index = start; index <= end; index++) {
                    document.querySelector("#data").innerHTML+=datas[index];
                    
                }
                  start =end;end+=100;
            }
        </script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza
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