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

259
Views
How can I keep the x-scroll position of a div, after inserting elements inside it?

I try to implement an infinite x-scroll with HTMX, but the request is infinitely triggered, because the triggering element gets inserted on the left side of the div and triggers a new request to load items inside the div.

How can I avoid that: append the new elements, but keep the x scroll position? It might be a CSS or a HTMX issue, I am not sure.

<div class="flex h-full space-x-2">
  <div class="bg-amber-600 flex-initial w-1/4"></div>
  <div class="flex space-x-2 w-full overflow-x-auto">
    <div class="flex-none w-16 ml-auto" 
      hx-get="/scroll" 
      hx-trigger="intersect once" 
      hx-swap="outerHTML">
    </div>
    <div class="bg-amber-400 flex-none w-16">0</div>
    <div class="bg-amber-400 flex-none w-16">1</div>
    <div class="bg-amber-400 flex-none w-16">2</div>
    <div class="bg-amber-400 flex-none w-16">3</div>
  </div>
</div>

I tried also with beforebegin and it behaves the same:

<div class="bg-amber-400 flex-none w-16 ml-auto"
  hx-get="/scroll"
  hx-trigger="intersect once"
  hx-swap="beforebegin">x</div>

Here is a codepen to explain what I mean: https://codepen.io/viggiesmalls/pen/RwQPROJ

about 4 years ago · Juan Pablo Isaza
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!