Created
March 22, 2024 15:26
-
-
Save michalvavra/6c05d105c36bbf2e92184988a0eb668b to your computer and use it in GitHub Desktop.
HTMX Loading Spinner with SVG & CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>HTMX Loading Spinner with SVG & CSS</title> | |
| <meta charset="utf-8"> | |
| <script src="https://unpkg.com/htmx.org@1.9.11"></script> | |
| <link rel="stylesheet" href="https://unpkg.com/@picocss/pico@2.0.6/css/pico.classless.min.css" /> | |
| <style> | |
| button { | |
| margin-right: 1rem; | |
| margin-bottom: 1.5rem; | |
| } | |
| .spinner { | |
| animation-name: spinner-animation; | |
| animation-duration: 6s; | |
| animation-timing-function: linear; | |
| animation-iteration-count: infinite; | |
| } | |
| @keyframes spinner-animation { | |
| 0% { | |
| transform: rotate(0deg); | |
| } | |
| 100% { | |
| transform: rotate(360deg); | |
| } | |
| } | |
| .feather { | |
| width: 24px; | |
| height: 24px; | |
| stroke: currentColor; | |
| stroke-width: 2; | |
| stroke-linecap: round; | |
| stroke-linejoin: round; | |
| fill: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <main> | |
| <h1>HTMX Loading Spinner with SVG & CSS</h1> | |
| <section> | |
| <form action="https://httpstat.us/200" hx-boost="true" hx-target="#form-result" hx-indicator="#form-spinner" | |
| hx-replace-url="false"> | |
| <fieldset> | |
| <label> | |
| Delay in milliseconds | |
| <input type="number" name="sleep" value="3000" /> | |
| </label> | |
| </fieldset> | |
| <button>Submit</button> | |
| <!-- | |
| Feather icon "loader", v4.29.1 | |
| https://feathericons.com/ | |
| MIT License - Copyright (c) 2013-2023 Cole Bemis | |
| --> | |
| <svg id="form-spinner" class="spinner feather htmx-indicator" xmlns="http://www.w3.org/2000/svg"> | |
| <line x1="12" y1="2" x2="12" y2="6"></line> | |
| <line x1="12" y1="18" x2="12" y2="22"></line> | |
| <line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line> | |
| <line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line> | |
| <line x1="2" y1="12" x2="6" y2="12"></line> | |
| <line x1="18" y1="12" x2="22" y2="12"></line> | |
| <line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line> | |
| <line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line> | |
| </svg> | |
| <!-- Alternatively, you can use SVG sprite. --> | |
| <!-- | |
| <svg id="form-spinner" class="spinner feather htmx-indicator"> | |
| <use href="feather-sprite.svg#loader" /> | |
| </svg> | |
| --> | |
| </form> | |
| </section> | |
| <section> | |
| <article id="form-result">No result. Click the button.</article> | |
| </section> | |
| </main> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment