better example

This commit is contained in:
Carson Gross 2023-03-31 13:53:16 -06:00
parent 2a2fc75c0a
commit c11b84120d
2 changed files with 24 additions and 12 deletions

View File

@ -81,11 +81,6 @@ Autorespond: <input id="autorespond" type="checkbox" onclick="toggleAutoRespond(
hx-swap="innerHTML transition:true">Issue Request</button>
<h1 id="h1">--</h1>
<script>
this.server.respondWith("GET", "/new-content", function(xhr){
xhr.respond(200, {}, "<h1>New Content</h1>")
});
</script>
<style>
@keyframes fade-in {
@ -126,6 +121,18 @@ Autorespond: <input id="autorespond" type="checkbox" onclick="toggleAutoRespond(
</button>
</div>
<script>
var originalContent = htmx.find(".slide-it").innerHTML;
this.server.respondWith("GET", "/new-content", function(xhr){
xhr.respond(200, {}, "<h1>Initial Content</h1> <button hx-get='/original-content' hx-swap='innerHTML transition:true' hx-target='closest div'>Restore It! </button>")
});
this.server.respondWith("GET", "/original-content", function(xhr){
xhr.respond(200, {}, originalContent)
});
</script>
</body>
</html>

View File

@ -295,12 +295,6 @@ implement this feature in the near future.
#### Demo
<script>
this.server.respondWith("GET", "/new-content", function(xhr){
xhr.respond(200, {}, "<h1>New Content</h1>")
});
</script>
<style>
@keyframes fade-in {
from { opacity: 0; }
@ -332,7 +326,6 @@ implement this feature in the near future.
}
</style>
<div class="slide-it">
<h1>Initial Content</h1>
<button hx-get="/new-content" hx-swap="innerHTML transition:true" hx-target="closest div">
@ -340,6 +333,18 @@ implement this feature in the near future.
</button>
</div>
<script>
var originalContent = htmx.find(".slide-it").innerHTML;
this.server.respondWith("GET", "/new-content", function(xhr){
xhr.respond(200, {}, "<h1>Initial Content</h1> <button hx-get='/original-content' hx-swap='innerHTML transition:true' hx-target='closest div'>Restore It! </button>")
});
this.server.respondWith("GET", "/original-content", function(xhr){
xhr.respond(200, {}, originalContent)
});
</script>
#### Conclusion
You can use the techniques above to create quite a few interesting and pleasing effects with plain old HTML while using htmx.