limited-teacher-83117
03/24/2023, 5:59 PMhx-on
discussion—how to attach event listeners to DOM elements declaratively, and let HTML/X handle the "gc" of it alllate-king-98305
03/24/2023, 6:01 PMadventurous-ocean-93733
03/24/2023, 8:47 PMgray-morning-3453
03/24/2023, 8:59 PMgray-morning-3453
03/24/2023, 9:00 PMrefined-manchester-67193
03/24/2023, 9:30 PMreveal
is getting triggered over and over again, even if the hidden trigger element isn't currently visible :/ripe-action-67367
03/24/2023, 9:32 PMrefined-manchester-67193
03/24/2023, 9:35 PMclass="absolute w-full h-[48rem] bottom-[2rem] text-white bg-red-500 pointer-events-none select-none"
But this triggered infinitely:
class="absolute w-full h-[48rem] bottom-[2rem] text-white hidden pointer-events-none select-none"
I'll do a few more tests because I'm going crazy.refined-manchester-67193
03/24/2023, 9:38 PMbg-red-500
with hidden
(display:none) causes htmx to keep triggering the revealed
event.refined-manchester-67193
03/24/2023, 9:38 PMopacity: 0
to get around this, but it's a little dirty.ripe-action-67367
03/24/2023, 9:38 PMbackground: transparent
?refined-manchester-67193
03/24/2023, 9:42 PMripe-action-67367
03/24/2023, 9:42 PMrefined-manchester-67193
03/24/2023, 9:42 PMopacity: 0
should also work as a workaroundripe-action-67367
03/24/2023, 9:46 PMhtml
<script src="https://demo.htmx.org"></script>
<div class="list">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="trigger" hx-trigger="revealed" hx-get="/foo" hx-swap="outerHTML"></div>
</div>
<template url="/foo">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="trigger" hx-trigger="revealed" hx-get="/foo" hx-swap="outerHTML"></div>
</template>
css
.list {
display: flex;
flex-direction: column;
gap: 10px;
position: relative;
}
.item {
background: purple;
height: 100px;
}
.trigger {
position: absolute;
background: transparent;
height: 300px;
bottom: 0;
right: 0;
width: 10px;
}
ripe-action-67367
03/24/2023, 9:46 PMripe-action-67367
03/24/2023, 9:48 PM.trigger
which is
1. Absolutely position to the side of the container, so it doesn't cover it, but scrolled together with the content
2. Placed as the last item of the container
3. Swapped with outerHTML
, which removes this trigger, which is not needed and places content where we want it to be (at the end of the container)ripe-action-67367
03/24/2023, 9:49 PMrefined-manchester-67193
03/24/2023, 9:51 PMrefined-manchester-67193
03/24/2023, 9:54 PMdisplay: none
on the triggering item makes it trigger without being revealed (it's not a big deal anyway)ripe-action-67367
03/24/2023, 9:55 PMripe-action-67367
03/24/2023, 9:56 PMvisibility: hidden
ripe-action-67367
03/24/2023, 9:56 PMripe-action-67367
03/24/2023, 9:56 PMrefined-manchester-67193
03/24/2023, 10:12 PMrefined-manchester-67193
03/24/2023, 10:13 PM/?page=3&org.htmx.cache-buster=true&org.htmx.cache-buster=true
Edit: Actually, it's only being appended twice. Not a big deal to me.fresh-midnight-60146
03/24/2023, 11:42 PMadventurous-ocean-93733
03/24/2023, 11:45 PMfresh-midnight-60146
03/25/2023, 12:01 AMfresh-midnight-60146
03/25/2023, 12:45 AM