Site: buildings lift on hover and focus, sink on press; ordered keyboard links

This commit is contained in:
ZacharyZhang-NY committed 2026-10-08 23:40:54 -04:00
1 parent 366f7529ba
commit 0f62a36182
5 files changed
+138 -8

No files matched your search

+24
View File
@@ -30,3 +30,27 @@
animation: none;
}
}
/* Interaction moves by translate; landing owns transform. */
.block {
transition: translate 0.15s ease-out;
}
.block[data-part] {
cursor: pointer;
outline: none;
}
.block.lifted {
translate: 0 calc(-1 * var(--step));
}
.block.lifted.pressed {
translate: 0 0;
}
@media (prefers-reduced-motion: reduce) {
.block {
transition: none;
}
}
+15 -7
View File
@@ -2,6 +2,7 @@ import "./style.css";
import "./iso.css";
import { block, stage } from "./iso.ts";
import { model } from "./model.ts";
import { touch } from "./touch.ts";
/** 112 BPM, the film's tempo; blocks land on sixteenths. */
const BEAT = 60 / 112;
@@ -10,21 +11,28 @@ const STEP = BEAT / 4;
const app = document.querySelector<HTMLElement>("#app");
if (!app) throw new Error("index.html has no #app");
const apps = model.slice(1, -1);
const parts = new Map<string, SVGGElement[]>();
const blocks: SVGGElement[] = [];
let beat = 1;
for (const part of model) {
part.blocks.forEach((spec, i) => {
const own = part.blocks.map((spec, i) => {
const g = block(spec);
g.style.setProperty("--land", `${(beat * BEAT + i * STEP).toFixed(3)}s`);
blocks.push(g);
return g;
});
if (apps.includes(part)) parts.set(part.name, own);
blocks.push(...own);
beat += Math.ceil(part.blocks.length / 4);
}
const title = document.createElement("h1");
title.textContent = "Ely Office";
const model3d = stage(blocks);
model3d.classList.add("grow");
model3d.setAttribute("role", "img");
model3d.setAttribute("aria-label", model.slice(1, -1).map((p) => p.name).join(", "));
app.append(title, model3d);
const host = document.createElement("div");
host.className = "model";
const svg = stage(blocks);
svg.classList.add("grow");
svg.setAttribute("aria-hidden", "true");
host.append(svg);
app.append(title, host);
touch(host, parts);
+38
View File
@@ -30,3 +30,41 @@ h1 {
max-width: 100%;
height: auto;
}
.model {
position: relative;
max-width: 100%;
}
.caption {
position: absolute;
margin: 0;
translate: -50% calc(-100% - 0.75rem);
font-size: 0.9375rem;
font-weight: 300;
color: #6e6e73;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transition: opacity 0.15s ease-out;
}
.caption.shown {
opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
.caption {
transition: none;
}
}
/* Keyboard and reader links; focus shows on the model. */
.doors a {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
+60
View File
@@ -0,0 +1,60 @@
// Buildings lift on hover or focus and sink when pressed.
import { UNIT } from "./iso.ts";
/** Links each app's blocks to its region, in reading order. */
export function touch(host: HTMLElement, parts: Map<string, SVGGElement[]>): void {
const caption = document.createElement("p");
caption.className = "caption";
caption.setAttribute("aria-hidden", "true");
host.append(caption);
host.style.setProperty("--step", `${UNIT / 2}px`);
const nav = document.createElement("nav");
nav.className = "doors";
host.append(nav);
for (const [name, blocks] of parts) {
const target = `#${name.toLowerCase()}`;
const inside = (node: EventTarget | null) =>
node instanceof Element && node.closest<SVGGElement>(".block")?.dataset.part === name;
const lift = (up: boolean) => {
for (const b of blocks) b.classList.toggle("lifted", up);
caption.classList.toggle("shown", up);
if (up) place(caption, host, blocks, name);
};
const press = (down: boolean) => {
for (const b of blocks) b.classList.toggle("pressed", down);
};
const open = () => {
press(false);
location.hash = target;
};
for (const b of blocks) {
b.dataset.part = name;
b.addEventListener("pointerenter", () => lift(true));
b.addEventListener("pointerleave", (e) => inside(e.relatedTarget) || (press(false), lift(false)));
b.addEventListener("pointerdown", () => press(true));
b.addEventListener("pointerup", open);
}
const door = document.createElement("a");
door.href = target;
door.textContent = name;
door.addEventListener("focus", () => lift(true));
door.addEventListener("blur", () => (press(false), lift(false)));
door.addEventListener("keydown", (e) => e.key === "Enter" && press(true));
door.addEventListener("click", () => press(false));
nav.append(door);
}
}
/** Puts the caption above the building's top. */
function place(caption: HTMLElement, host: HTMLElement, blocks: SVGGElement[], name: string) {
const origin = host.getBoundingClientRect();
const rects = blocks.map((b) => b.getBoundingClientRect());
const left = Math.min(...rects.map((r) => r.left));
const right = Math.max(...rects.map((r) => r.right));
const top = Math.min(...rects.map((r) => r.top));
caption.textContent = name;
caption.style.left = `${(left + right) / 2 - origin.left}px`;
caption.style.top = `${top - origin.top}px`;
}