mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00
4.1 KiB
4.1 KiB
layout |
---|
demo_layout.njk |
Progress Bar
This example shows how to implement a smoothly scrolling progress bar.
We start with an intial state with a button that issues a POST
to /start
to begin the job:
<div kt-target="this" kt-swap="outerHTML">
<h3>Start Progress</h3>
<button class="btn" kt-post="/start">
Start Job
</button>
</div>
This div is then replaced with a new div that reloads itself every 600ms:
<div kt-target="this"
kt-get="/job"
kt-trigger="load delay:600ms"
kt-swap="outerHTML">
<h3>Running</h3>
<div class="progress">
<div id="pb" class="progress-bar" style="width:0%">
</div>
</div>
This HTML is rerendered every 600 milliseconds, with the "width" style attribute on the progress bar being updated. Because there is an id on the progress bar div, kutty will smoothly transition between requests by settling the style attribute into its new value. This, when coupled with CSS transitions, make the visual transition continuous rather than jumpy.
Finally, when the process is complete, a restart button is added to the UI:
<div kt-target="this"
kt-get="/job"
kt-trigger="none"
kt-swap="outerHTML">
<h3>Complete</h3>
<div class="progress">
<div id="pb" class="progress-bar" style="width:100%">
</div>
</div>
<button id="restart-btn" class="btn" kt-post="/start" kt-classes="add show:600ms">
Restart Job
</button>
{% include demo_ui.html.liquid %}