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

346
Visualizações
How to load more data when scroll from bottom to top jquery \ js

I'm working on a live chat on a dating site. So, I have a question, how I can load more data (ajax) when scrolling reaches the top of the chat(div) on a mobile device. I need only jquery \ vanilla js logic.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

HTML CODE

 <div class="chat-list" id="messages" #scrollMe [scrollTop]="scrolltop" (scroll)="onScrollChat()">
      <div *ngFor="let message of Chats;let i = index">
      </div>
 </div>

JS Here we have note the scrolltop position [old_height] before loading data.Once the data is loaded on scroll we have to get new scrolltop position[new_height]. scrollTop will be ele.scrollTop = new_height - old_height

*note: don't put style scroll-behaviour:smooth

onScrollChat() {
    if (this.selectedTab != 0) {
      let ele = document.getElementById('messages');
      let old_height = ele.scrollHeight; // getting height before loading more messages

      if (ele.scrollTop == 0) {
      //call chat api to load more messages
            this.tempMsgs = data;//loaded messages
            this.Chats = this.tempMsgs.concat(this.Chats)
            this.changeDetectionRef.detectChanges();
            let new_height = ele.scrollHeight
            ele.scrollTop = new_height - old_height;
      }
    }
  }
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