# Capítulos al desplazarse

Un cartel cambia mientras lees cada etapa de su producción.

## Cómo probarlo

Recorre las notas de producción o selecciona una etapa por su nombre.

## Detalles de la interacción

La vista del cartel tiene una etapa correspondiente al boceto, otra a las planchas de color y otra a la impresión.

## Controles por plataforma

- iOS · Desliza hacia arriba por el texto o toca una etapa para ver cómo cambia el cartel.
- Android · Desliza hacia arriba por el texto o toca una etapa para ver cómo cambia el cartel.
- PC · Recorre las notas de producción o selecciona una etapa por su nombre.

## Dónde usarlo

Textos en los que cada pasaje explica una ilustración o un cambio en ella.

## Instrucciones de implementación

> Sincroniza la ilustración y el capítulo activo tanto al desplazarse como al elegir un capítulo.

## Fuentes y créditos

La navegación por capítulos se inspira en The Boat. UI Motion Lab creó el cartel y las imágenes de las etapas de impresión para este ejemplo.

- [The Boat, de SBS Australia](<https://www.sbs.com.au/theboat/>)
- [Notas de producción de Distil](<https://www.distil.im/projects/the-boat>)
- [Ficha del proyecto en Awwwards](<https://www.awwwards.com/sites/the-boat>)

## Cómo comprobar el resultado

En una pantalla ancha, el cartel permanece visible junto al texto. Recorre las tres etapas desplazándote o usando los enlaces a los capítulos. Comprueba que la ilustración, el capítulo activo y la posición de lectura coinciden después de seguir un enlace. The Boat recibió el premio Site of the Day de Awwwards el 7 de mayo de 2015.

## Ejemplo en HTML

Guarda el siguiente código en un archivo HTML y ábrelo en tu navegador. Puedes usar el ejemplo sin conexión.

```html
<!doctype html>
<html lang="es"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Imágenes persistentes · Capítulos al desplazarse</title>
<script>
const labSettings=new URLSearchParams(location.search);
document.documentElement.classList.toggle('lab-embedded',labSettings.get('embed')==='1');
document.documentElement.classList.toggle('lab-reduce',labSettings.get('reduce')==='1');
</script>

<style>*{box-sizing:border-box}
:root{--paper:#eeeadc;--ink:#292c22;--muted:#666858;--accent:#9e3f26;color-scheme:light}
body{margin:0;background:var(--paper);color:var(--ink);font:15px/1.5 Inter,Pretendard,"Malgun Gothic",system-ui,sans-serif}
main{max-width:1200px;margin:0 auto;padding:clamp(22px,4vw,58px) clamp(16px,4vw,58px) 60px}
.intro{max-width:65ch;margin-bottom:24px}.intro h1{font-size:clamp(27px,4.5vw,55px);letter-spacing:-.07em;line-height:1.12;margin:0 0 8px}.intro p{margin:0;color:var(--muted)}
.pressroom{display:grid;grid-template-columns:minmax(0,1.58fr) minmax(180px,.75fr);align-items:start;gap:clamp(18px,4vw,66px)}
.mount{position:sticky;top:18px;margin:0;min-width:0;background:#d1cfbe;box-shadow:inset 0 1px #fff6}
.art{width:100%;height:clamp(240px,65vh,630px);display:flex;align-items:center;justify-content:center;background:linear-gradient(130deg,#dad9cc,#c9c6b5)}
.paper{position:relative;aspect-ratio:3/4;height:85%;max-width:88%;background:#f8f0d8;transform:rotate(-1.2deg);box-shadow:1px 1px 0 #817859,3px 6px 10px #35352636}
canvas{position:absolute;inset:0;width:100%;height:100%;opacity:0;transition:opacity .27s ease-out}
figure[data-scene="sketch"] .pass-sketch,figure[data-scene="ink"] .pass-ink,figure[data-scene="print"] .pass-print{opacity:1}
figcaption{display:flex;justify-content:space-between;align-items:center;border-top:1px solid #abaa95;color:#4a4e3c;padding:8px 12px;font:550 10px/1.4 Consolas,monospace;letter-spacing:.045em}
figcaption strong{font:650 12px/1.3 Inter,Pretendard,system-ui,sans-serif;letter-spacing:0}
main nav{position:sticky;top:0;z-index:2;display:flex;gap:0;padding:0;background:var(--paper);border-bottom:1px solid #aaa994;margin:0}
main nav a{color:var(--muted);padding:12px 9px;font-weight:650;font-size:12px;text-decoration:none;white-space:nowrap;border-bottom:2px solid transparent}
main nav a:first-child{padding-left:0}main nav a[aria-current]{color:var(--accent);border-bottom-color:var(--accent)}
section.chapter{min-height:74vh;padding:clamp(24px,5vw,80px) 0;scroll-margin-top:45px;border-bottom:1px solid #b8b7a5}
.chapter .sequence{font:550 11px/1.2 Consolas,monospace;color:#615b45;letter-spacing:.06em}
.chapter h2{font-size:clamp(22px,3vw,38px);line-height:1.12;letter-spacing:-.065em;margin:10px 0 12px}
.chapter p{font-size:clamp(13px,1.35vw,17px);line-height:1.65;margin:0;word-break:keep-all}
.lab-embedded .intro{display:none}
.lab-embedded main{padding-top:clamp(16px,2vw,28px)}
.lab-reduce *{transition:none!important;scroll-behavior:auto!important}
a:focus-visible{outline:3px solid #875032;outline-offset:2px}
@media(max-width:600px){
 main{padding:16px 16px 36px}.intro{margin:8px 0 18px}
 .pressroom{display:flex;flex-direction:column;gap:0}
 .mount{top:0;width:100%;z-index:2;--art-height:clamp(125px,43vh,330px)}
 .art{height:var(--art-height)}figcaption{padding:5px 9px}
 .chapters{width:100%}main nav{top:calc(clamp(125px,43vh,330px) + 27px);background:var(--paper);z-index:2}
 main nav a{padding:10px 13px}.lab-embedded main{padding:0 12px 30px}.lab-embedded .mount{width:calc(100% + 24px);margin-inline:-12px}
 section.chapter{min-height:66vh;padding:17px 2px 50px;scroll-margin-top:calc(clamp(125px,43vh,330px) + 78px)}
}
@media(max-height:380px){.pressroom{display:grid;grid-template-columns:minmax(0,1fr) minmax(150px,.8fr);gap:18px}.art{height:70vh}.mount{width:auto!important;margin:0!important;top:0}.chapters nav{top:0}section.chapter{scroll-margin-top:42px}}
@media(prefers-reduced-motion:reduce){canvas{transition:none}}</style></head>
<body class="lab-example">

<main><header class="intro"><h1>Imágenes persistentes</h1><p>Recorre las tres etapas de creación del cartel: dibujo, registro e impresión.</p></header>
<div class="pressroom"><figure class="mount" data-scene="sketch" role="img" aria-label="Etapas del cartel Imágenes persistentes">
  <div class="art"><div class="paper"><canvas class="pass-sketch" aria-hidden="true"></canvas><canvas class="pass-ink" aria-hidden="true"></canvas><canvas class="pass-print" aria-hidden="true"></canvas></div></div>
  <figcaption><strong>Boceto</strong><span>PLATE 01 / 03</span></figcaption>
</figure><div class="chapters"><nav aria-label="Etapa de producción"><a href="#sketch" aria-current="step">Boceto</a><a href="#ink">Planchas</a><a href="#print">Estampa</a></nav>
<section id="sketch" class="chapter"><span class="sequence">01 / 03</span><h2>Boceto</h2><p>Dibuja tres capas de crestas y sitúa el sol detrás de la más lejana. La distancia entre las curvas da profundidad a las montañas.</p></section>
<section id="ink" class="chapter"><span class="sequence">02 / 03</span><h2>Planchas</h2><p>Imprime primero el sol y la cresta lejana en bermellón. En la cresta intermedia, la segunda plancha da un tono verde donde se superponen las tintas.</p></section>
<section id="print" class="chapter"><span class="sequence">03 / 03</span><h2>Estampa</h2><p>Imprime al final el primer plano oscuro y el título. Las líneas finas que quedan del color del papel definen la cresta.</p></section>
</div></div></main>

<script>
const passes = ['sketch','ink','print'];

// All marks and contours are drawn from this composition. Render the three
// plates once so scrolling only crossfades between finished canvases.
function drawPoster(canvas, pass) {
  const c = canvas.getContext('2d');
  if (!c) return;
  const W=720, H=960;
  canvas.width=W; canvas.height=H;
  let state=863171;
  const noise=()=>{state=(Math.imul(state,1664525)+1013904223)>>>0;return state/4294967296};
  const ink=pass==='sketch'?'#897f65':'#273c36';
  const completed=pass==='print';
  c.fillStyle='#f3e8c9';c.fillRect(0,0,W,H);
  for (let i=0;i<17500;i++) {
    const dotSize=noise()*2.4+.5;
    c.fillStyle=noise()>.5?'rgba(85,58,26,.075)':'rgba(255,255,240,.22)';
    c.fillRect(noise()*W,noise()*H,dotSize,dotSize*.58);
  }
  const text=(s,x,y,font,color,align='left')=>{c.font=font;c.fillStyle=color;c.textAlign=align;c.fillText(s,x,y)};
  const rule=(x1,y1,x2,y2,color,width=1)=>{c.beginPath();c.moveTo(x1,y1);c.lineTo(x2,y2);c.strokeStyle=color;c.lineWidth=width;c.stroke()};
  const top=155,bottom=779,left=42,right=W-42;
  const field=() => {c.beginPath();c.rect(left,top,right-left,bottom-top);c.clip()};
  const pencil='#988c71';
  c.save();field();
  if(pass==='sketch'){
    for(let x=left;x<right;x+=52)rule(x,top,x,bottom,'#c1b499',.55);
    for(let y=top;y<bottom;y+=52)rule(left,y,right,y,'#c1b499',.55);
  }
  const cx=442,cy=360,r=151;
  c.save();c.beginPath();c.arc(cx,cy,r,0,Math.PI*2);c.clip();
  if(pass!=='sketch'){c.fillStyle=completed?'#c95330':'#d96b3d';c.fillRect(cx-r,cy-r,2*r,2*r)}
  for(let y=-r;y<=r;y+=5){
    const chord=Math.sqrt(r*r-y*y);
    const drift=2.8*Math.sin(y*.065);
    rule(cx-chord+drift,cy+y,cx+chord,cy+y+(pass==='sketch'?0:3),pass==='sketch'?'#a79a7f':'#efae72',pass==='sketch'?.5:.85);
  }
  c.restore();
  c.beginPath();c.arc(cx,cy,r,0,Math.PI*2);c.lineWidth=1;c.strokeStyle=pass==='sketch'?pencil:'#c46c43';c.stroke();
  function crest(x,ridge) {
    const a=x/W;
    return [515,626,716][ridge]-[91,107,75][ridge]*Math.sin(a*4.15+ridge*.68)
      +26*Math.sin(a*10.5+ridge*1.31)+12*Math.sin(a*19.3+.75*ridge)+5*Math.sin(a*39.1+.6*ridge);
  }
  for(let ridge=0;ridge<3;ridge++){
    const outline=()=>{c.beginPath();for(let x=left;x<=right+4;x+=3){const y=crest(x,ridge);if(x===left)c.moveTo(x,y);else c.lineTo(x,y)}};
    c.save();outline();c.lineTo(right+5,bottom+2);c.lineTo(left-2,bottom+2);c.closePath();
    c.fillStyle=pass==='sketch'?'#eee4c7':(completed?['#d58856','#768471','#283e37']:['#d89b65','#ab9b68','#758875'])[ridge];
    c.fill();c.clip();
    for(let j=0;j<105;j++){
      c.beginPath();
      for(let x=left-2;x<=right+3;x+=4){
        const d=j*(completed?4.2:5.2);
        const y=crest(x,ridge)+d+Math.sin(x*.021+j*.11)*Math.min(13,j*.38)+Math.sin(x*.061+j)*.8;
        if(x===left-2)c.moveTo(x,y);else c.lineTo(x,y);
      }
      c.strokeStyle=pass==='sketch'?'rgba(107,98,73,.46)':(completed?['#a6653f','#4d6c60','#a8ad8e'][ridge]:['#9f714d','#607664','#c2b68e'][ridge]);
      c.lineWidth=pass==='sketch'?.75:(ridge===2?1.35:1.1);
      c.stroke();
    }
    c.restore();outline();c.strokeStyle=pass==='sketch'?pencil:ink;c.lineWidth=pass==='sketch'?.8:1.25;c.stroke();
  }
  c.restore();
  [left,right].forEach(x=>[top,bottom].forEach(y=>{rule(x-8,y,x+8,y,'#635d4d',1);rule(x,y-8,x,y+8,'#635d4d',1)}));
  text('MOTION LAB   /   PRINT STUDIES',left,56,'600 14px Consolas, monospace',ink);
  text('EDITION 01',right,56,'600 14px Consolas, monospace',ink,'right');
  rule(left,76,right,76,'#8e8469',1);
  text('AFTERIMAGE',left,129,'bold 51px Georgia, serif',pass==='sketch'?'#93896f':ink);
  if(completed){
    text('Imágenes persistentes',left,866,'bold 67px "Malgun Gothic", sans-serif',ink);
    text('Landscape',right,837,'italic 30px Georgia, serif',ink,'right');
    text('in three plates.',right,870,'italic 30px Georgia, serif',ink,'right');
  } else {
    c.save();c.strokeStyle=pencil;c.lineWidth=1;c.font='bold 67px "Malgun Gothic",sans-serif';c.textAlign='left';c.strokeText('Imágenes persistentes',left,866);c.restore();
    for(let y=821;y<862;y+=13)rule(right-120,y,right,y,pencil,1);
  }
  rule(left,901,right,901,'#8e8469',1);
  text('FIELD NOTES  /  LANDSCAPE NO.01',left,929,'600 14px Consolas, monospace',ink);
  text('ML–053',right,929,'600 14px Consolas, monospace',ink,'right');
}
passes.forEach(name=>drawPoster(document.querySelector('.pass-'+name),name));
const chapters = Array.from(document.querySelectorAll('.chapter'));
const links = Array.from(document.querySelectorAll('main nav a'));
const figure = document.querySelector('figure');
const caption = figure.querySelector('figcaption');
let pending = false;
function updateScene(){
  pending = false;
  const narrow = innerWidth<=600 && innerHeight>380;
  const navBottom = document.querySelector('main nav').getBoundingClientRect().bottom;
  const marker = narrow ? Math.min(innerHeight-4,Math.max(innerHeight*.48,navBottom+21)) : innerHeight*.46;
  let index = 0;
  for(let i=1;i<chapters.length;i++) if(chapters[i].getBoundingClientRect().top<=marker) index=i;
  if(scrollY+innerHeight >= document.documentElement.scrollHeight-2) index=chapters.length-1;
  const chapter = chapters[index], name=chapter.querySelector('h2').textContent;
  figure.dataset.scene=chapter.id;
  figure.setAttribute('aria-label','Cartel Imágenes persistentes, '+name);
  caption.querySelector('strong').textContent=name;
  caption.querySelector('span').textContent='PLATE 0'+(index+1)+' / 03';
  links.forEach((link,i)=>{if(i===index)link.setAttribute('aria-current','step');else link.removeAttribute('aria-current')});
}
function schedule(){if(!pending){pending=true;requestAnimationFrame(updateScene)}}
window.addEventListener('scroll',schedule,{passive:true});
window.addEventListener('resize',schedule);
window.addEventListener('pageshow',schedule);
window.addEventListener('hashchange',schedule);
updateScene();
</script></body></html>
```
