Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
Cómo cargar más datos cuando se desplaza de abajo hacia arriba jquery \ js

Estoy trabajando en un chat en vivo en un sitio de citas. Entonces, tengo una pregunta, ¿cómo puedo cargar más datos (ajax) cuando el desplazamiento llega a la parte superior del chat (div) en un dispositivo móvil? Solo necesito jquery \ vanilla js logic.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

CÓDIGO HTML

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

JS Aquí tenemos nota de la posición de la parte superior del desplazamiento [old_height] antes de cargar los datos. Una vez que los datos se cargan en el desplazamiento, tenemos que obtener una nueva posición de la parte superior del desplazamiento [new_height]. scrollTop será ele.scrollTop = new_height - old_height

*nota: no pongas estilo 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!