Deep links and the back button
Opening a slide adds #dlb=<id> to the URL, so the back button closes the box instead of leaving the page, and a link to that hash opens the slide, from anywhere on the page or from another site.
data-dlb-id gives a slide an id that stays when the order changes.
live · Deep links and the back button
Straight to the amber stripes, or to the soft bands.
<div id="linked" class="row">
<a href="/media/photo-7-1600.jpg" data-dlb-id="soft" data-dlb-width="1600" data-dlb-height="1066"><img src="/media/photo-7-480.jpg" alt="Soft bands of violet, yellow, mint and purple" /></a>
<a href="/media/photo-4-1600.jpg" data-dlb-id="amber" data-dlb-width="1066" data-dlb-height="1600"><img src="/media/photo-4-480.jpg" alt="Amber stripes across dark red" /></a>
</div>
<p>Straight to <a href="#dlb=amber">the amber stripes</a>, or to <a href="#dlb=soft">the soft bands</a>.</p>/* A row of thumbnails, 7rem high */
.row {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.row img {
display: block;
width: auto;
height: 7rem;
}import { lightbox } from "dialog-lightbox";
// history is on by default: opening adds #dlb=<id> to the URL, and the back button closes the box
lightbox({ gallery: document.querySelector("#linked"), dialog: document.querySelector("dialog.box") });
