← AE Lab
▶
Explicado paso a paso en el episodio
5 efectos web que tus clientes no han visto nunca (el nº1 enciende la luz)
8:54La cuerda de la luz
Cuerda de la luz
Una lámpara cuelga del techo como un péndulo, con su cadena de bolitas metálicas. Tira de la gota hasta oír el clic: la bombilla titila, se enciende un cono de luz con polvo flotando y la página pasa a tema claro desde la bombilla. La sombra del titular sigue a la luz.
// CÓMO ESTÁ HECHO
- La lámpara es un péndulo: la gravedad la devuelve al centro y, si tiras de la cadena hacia un lado, el par (r × F) la inclina.
- La cadena son 18 bolitas con física de Verlet: cada una sigue su inercia y 16 pasadas por fotograma corrigen las distancias.
- Al estirar más de 38 px suena el clic (ruido filtrado con Web Audio, sin archivos) y vibra; la luz cambia al soltar, como un interruptor de verdad.
- El tema claro se abre con View Transitions desde la bombilla; el cono, el polvo y la sombra del titular se recalculan cada fotograma.
// EL CÓDIGO
<div class="escena">
<div class="contenido">
<div class="estado"><i aria-hidden="true"></i><span class="solo-sombra">LUZ · OFF</span><span class="solo-luz">LUZ · ON</span></div>
<h1><span class="solo-sombra">Tira de la cuerda</span><span class="solo-luz">Se hizo la luz</span><span>_</span></h1>
<p class="solo-sombra">Agarra la gota y tira hasta oír el clic. También puedes empujar la lámpara.</p>
<p class="solo-luz">Tema claro. La sombra del titular sigue a la bombilla: mueve la lámpara y verás.</p>
<div class="chips"><span>física Verlet</span><span>péndulo</span><span>View Transitions</span><span>Web Audio</span></div>
</div>
<canvas id="lienzo" aria-hidden="true"></canvas>
<div class="pista" id="pista" aria-hidden="true">tira <b>↓</b></div>
<div class="controles">
<button id="tirar" type="button" aria-pressed="false">Encender la luz</button>
<button id="sonido" type="button" aria-pressed="true">Sonido: sí</button>
</div>
</div>
:root {
--fondo: #05070A;
--texto: #E8F5EE;
--suave: #7C8A82;
--verde: #00FF7F;
--tarjeta: rgba(13, 20, 16, .8);
--borde: #1B2A21;
--bx: 70vw; /* dónde está la bombilla (lo actualiza el JS en cada fotograma) */
--by: 30vh;
--luz: 0; /* intensidad de la luz, de 0 a 1 */
}
:root.luz {
--fondo: #F2F5F3;
--texto: #05070A;
--suave: #4A5650;
--verde: #00873F;
--tarjeta: rgba(255, 255, 255, .75);
--borde: #D5DED9;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
color: var(--texto);
font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
overflow: hidden;
-webkit-tap-highlight-color: transparent;
/* La habitación: un poco más clara justo debajo de la bombilla */
background: radial-gradient(circle at var(--bx) var(--by), #0C1712 0, #05070A 46%) fixed;
}
:root.luz body {
background: radial-gradient(circle at var(--bx) var(--by), #FFFFFF 0, #F4F7F5 30%, #DCE3DF 100%) fixed;
}
.escena { position: relative; height: 100dvh; display: grid; align-content: center; padding: 0 8vw; }
.contenido { position: relative; z-index: 1; max-width: 600px; }
.estado {
display: inline-flex; align-items: center; gap: 8px; margin-bottom: 18px;
font: 600 12px ui-monospace, "JetBrains Mono", monospace; letter-spacing: .14em; color: var(--suave);
}
.estado i { width: 8px; height: 8px; border-radius: 50%; background: #2A3A31; transition: background .3s, box-shadow .3s; }
:root.luz .estado i { background: var(--verde); box-shadow: 0 0 10px var(--verde); }
h1 {
font: 800 clamp(38px, 7.4vw, 92px)/.98 ui-monospace, "JetBrains Mono", monospace;
letter-spacing: -.05em;
/* Sombra que cae lejos de la bombilla: --sx y --sy los calcula el JS */
text-shadow: var(--sx, 0) var(--sy, 0) 14px rgba(5, 7, 10, calc(var(--luz) * .22));
}
h1 span { color: var(--verde); }
.contenido p { color: var(--suave); margin-top: 16px; line-height: 1.6; max-width: 38ch; font-size: 16px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }
.chips span {
background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 999px;
padding: 7px 13px; font: 12px ui-monospace, "JetBrains Mono", monospace; color: var(--suave);
backdrop-filter: blur(6px);
}
.solo-luz { display: none; }
:root.luz .solo-luz { display: inline; }
:root.luz .solo-sombra { display: none; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; touch-action: none; }
.pista {
position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none;
font: 700 12px ui-monospace, "JetBrains Mono", monospace; letter-spacing: .1em; color: var(--verde);
opacity: 0; transition: opacity .5s;
}
.pista.ver { opacity: 1; }
.pista b { display: inline-block; animation: pista 1.2s ease-in-out infinite; }
@keyframes pista { 50% { transform: translateY(5px); } }
.controles { position: absolute; left: 8vw; bottom: 26px; z-index: 4; display: flex; gap: 8px; }
.controles button {
appearance: none; border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto);
font: 600 12px ui-monospace, "JetBrains Mono", monospace; border-radius: 999px; padding: 10px 15px; cursor: pointer;
backdrop-filter: blur(6px);
}
.controles button:focus-visible { outline: 2px solid var(--verde); outline-offset: 3px; }
@media (max-width: 700px) {
.escena { align-content: end; padding-bottom: 92px; }
.contenido p { font-size: 15px; }
}
/* Cambio de tema: un círculo de luz que nace en la bombilla (o se apaga hacia ella) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.encendiendo::view-transition-new(root) { animation: luz-abre .75s cubic-bezier(.6, 0, .2, 1); }
html.apagando::view-transition-old(root) { z-index: 2; animation: luz-cierra .55s cubic-bezier(.6, 0, .2, 1) both; }
@keyframes luz-abre { from { clip-path: circle(0 at var(--vx) var(--vy)); } to { clip-path: circle(160vmax at var(--vx) var(--vy)); } }
@keyframes luz-cierra { from { clip-path: circle(160vmax at var(--vx) var(--vy)); } to { clip-path: circle(0 at var(--vx) var(--vy)); } }
@media (prefers-reduced-motion: reduce) {
.pista b { animation: none; }
}
(() => {
const lienzo = document.getElementById('lienzo');
const ctx = lienzo.getContext('2d');
const raiz = document.documentElement;
const h1 = document.querySelector('h1');
const pista = document.getElementById('pista');
const botonLuz = document.getElementById('tirar');
const botonSonido = document.getElementById('sonido');
const quieto = matchMedia('(prefers-reduced-motion: reduce)').matches;
let W = 0, H = 0;
const N = 18; // bolitas de la cadena
let largo = 9; // distancia entre bolitas
let reposo = 0; // largo de la cadena sin estirar
const UMBRAL = 38; // px de estirón para que haga «clic»
// ---------- Lámpara: un péndulo colgado del techo ----------
const lamp = { px: 0, py: -8, L: 140, th: 0, w: 0 };
const lampTop = () => ({ x: lamp.px + Math.sin(lamp.th) * lamp.L, y: lamp.py + Math.cos(lamp.th) * lamp.L });
// Pasa un punto del dibujo de la lámpara (lx, ly) a la pantalla, girado con ella
function mundo(lx, ly) {
const t = lampTop(), a = -lamp.th, c = Math.cos(a), s = Math.sin(a);
return { x: t.x + lx * c - ly * s, y: t.y + lx * s + ly * c };
}
const ANCLA = [30, 60]; // de dónde sale la cadena (al lado de la bombilla)
const BOMBILLA = [0, 66];
// ---------- Cadena (física de Verlet) ----------
let p = [];
let agarrado = false, agarradaLampara = false, puntero = { x: 0, y: 0 }, inicio = null, movido = 0;
let tirando = 0, armado = false, nuncaTirado = true, ultimoToque = performance.now();
// ---------- Luz ----------
let encendida = false, intensidad = 0, encendidaEn = 0;
const polvo = Array.from({ length: 70 }, () => ({ x: Math.random(), y: Math.random(), vx: 0, vy: 0, r: .6 + Math.random() * 1.6 }));
function medir() {
const dpr = Math.min(devicePixelRatio || 1, 2);
W = innerWidth; H = innerHeight;
lienzo.width = W * dpr; lienzo.height = H * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
const movil = W < 700;
lamp.px = W * (movil ? .66 : .7);
lamp.L = movil ? Math.max(70, H * .13) : Math.min(H * .2, 170);
largo = movil ? 8 : 9.5;
reposo = largo * (N - 1);
const a = mundo(...ANCLA);
p = Array.from({ length: N }, (_, i) => ({ x: a.x, y: a.y + i * largo, px: a.x, py: a.y + i * largo }));
}
function fisica(t) {
// Péndulo: la gravedad lo devuelve al centro, el rozamiento lo frena y una brisa lo mece
let par = -Math.sin(lamp.th) * .0026;
if (!quieto) par += Math.sin(t / 1400) * .000018;
const a = mundo(...ANCLA);
const u = p[N - 1];
// Si tiras de la cadena hacia un lado, la lámpara se inclina (par = r × F)
if (agarrado || tirando) {
const dx = u.x - a.x, dy = u.y - a.y, d = Math.hypot(dx, dy) || 1;
const tension = Math.max(0, d - reposo * .92);
const rx = a.x - lamp.px, ry = a.y - lamp.py;
par += (rx * (dy / d) * tension - ry * (dx / d) * tension) * -6e-8;
}
if (agarradaLampara) {
const objetivo = Math.atan2(puntero.x - lamp.px, puntero.y - lamp.py);
par += (Math.max(-.9, Math.min(.9, objetivo)) - lamp.th) * .02;
}
lamp.w = (lamp.w + par) * .985;
lamp.th += lamp.w;
// Cadena
for (let i = 1; i < N; i++) {
const q = p[i];
const vx = (q.x - q.px) * .985, vy = (q.y - q.py) * .985;
q.px = q.x; q.py = q.y;
q.x += vx; q.y += vy + .42;
}
if (agarrado || tirando) {
let obj = agarrado ? puntero : { x: a.x + 6, y: a.y + reposo + 72 };
const dx = obj.x - a.x, dy = obj.y - a.y, d = Math.hypot(dx, dy), max = reposo * 1.5;
if (d > max) obj = { x: a.x + dx / d * max, y: a.y + dy / d * max };
u.x = obj.x; u.y = obj.y;
}
for (let k = 0; k < 16; k++) {
p[0].x = a.x; p[0].y = a.y;
for (let i = 0; i < N - 1; i++) {
const A = p[i], B = p[i + 1];
const dx = B.x - A.x, dy = B.y - A.y, d = Math.hypot(dx, dy) || 1;
const dif = (d - largo) / d * .5;
if (i > 0) { A.x += dx * dif; A.y += dy * dif; }
if (!((agarrado || tirando) && i + 1 === N - 1)) { B.x -= dx * dif; B.y -= dy * dif; }
}
}
// ¿Ha llegado al fondo? El interruptor hace clic (y la luz cambia al soltar)
const estiron = Math.hypot(u.x - a.x, u.y - a.y) - reposo;
if ((agarrado || tirando) && !armado && estiron > UMBRAL) {
armado = true;
sonar(true);
if (navigator.vibrate) navigator.vibrate(12);
}
if (tirando && --tirando === 0) soltar();
// Luz: al encender, la bombilla titila antes de quedarse fija
if (encendida) {
const ms = t - encendidaEn;
const curva = quieto ? 1 : ms < 40 ? .9 : ms < 95 ? .12 : ms < 150 ? .75 : ms < 205 ? .3 : Math.min(1, .3 + (ms - 205) / 260);
intensidad = curva;
} else {
intensidad *= .82;
}
// Polvo flotando
for (const g of polvo) {
g.vx += (Math.random() - .5) * .00004; g.vy += (Math.random() - .5) * .00004 - .000004;
g.vx *= .98; g.vy *= .98;
g.x = (g.x + g.vx + 1) % 1; g.y = (g.y + g.vy + 1) % 1;
}
}
function dibujar(t) {
ctx.clearRect(0, 0, W, H);
const luz = raiz.classList.contains('luz');
const top = lampTop();
const b = mundo(...BOMBILLA);
const eje = { x: Math.sin(lamp.th), y: Math.cos(lamp.th) };
// Variables para el CSS: fondo iluminado y sombra del titular
raiz.style.setProperty('--bx', b.x.toFixed(0) + 'px');
raiz.style.setProperty('--by', b.y.toFixed(0) + 'px');
raiz.style.setProperty('--luz', intensidad.toFixed(3));
const r = h1.getBoundingClientRect();
const hx = r.left + r.width / 2 - b.x, hy = r.top + r.height / 2 - b.y, hd = Math.hypot(hx, hy) || 1;
h1.style.setProperty('--sx', (hx / hd * 12).toFixed(1) + 'px');
h1.style.setProperty('--sy', (hy / hd * 12).toFixed(1) + 'px');
// Cono de luz y polvo
if (intensidad > .01) {
const ang = .5, lon = Math.max(W, H) * 1.3;
const izq = { x: b.x + (eje.x * Math.cos(ang) - eje.y * Math.sin(ang)) * lon, y: b.y + (eje.x * Math.sin(ang) + eje.y * Math.cos(ang)) * lon };
const der = { x: b.x + (eje.x * Math.cos(-ang) - eje.y * Math.sin(-ang)) * lon, y: b.y + (eje.x * Math.sin(-ang) + eje.y * Math.cos(-ang)) * lon };
const gr = ctx.createLinearGradient(b.x, b.y, b.x + eje.x * H, b.y + eje.y * H);
gr.addColorStop(0, `rgba(255, 250, 225, ${(luz ? .55 : .3) * intensidad})`);
gr.addColorStop(1, 'rgba(255, 250, 225, 0)');
ctx.fillStyle = gr;
ctx.beginPath(); ctx.moveTo(b.x - eje.y * 26, b.y + eje.x * 26); ctx.lineTo(izq.x, izq.y); ctx.lineTo(der.x, der.y); ctx.lineTo(b.x + eje.y * 26, b.y - eje.x * 26); ctx.closePath(); ctx.fill();
for (const g of polvo) {
const x = g.x * W, y = g.y * H, dx = x - b.x, dy = y - b.y, d = Math.hypot(dx, dy) || 1;
const coseno = (dx * eje.x + dy * eje.y) / d;
if (coseno < Math.cos(ang)) continue;
const a = intensidad * (coseno - Math.cos(ang)) / (1 - Math.cos(ang)) * Math.max(0, 1 - d / (H * 1.1));
ctx.fillStyle = luz ? `rgba(196, 160, 70, ${a * .55})` : `rgba(255, 245, 210, ${a * .8})`;
ctx.beginPath(); ctx.arc(x, y, g.r, 0, Math.PI * 2); ctx.fill();
}
}
// Cable
ctx.strokeStyle = luz ? '#3E4A44' : '#26332C';
ctx.lineWidth = 2;
ctx.beginPath(); ctx.moveTo(lamp.px, -10); ctx.lineTo(top.x, top.y); ctx.stroke();
// Lámpara (dibujada en su propio sistema, girada con el péndulo)
ctx.save();
ctx.translate(top.x, top.y);
ctx.rotate(-lamp.th);
ctx.fillStyle = '#1C2822';
ctx.fillRect(-7, 0, 14, 14);
const metal = ctx.createLinearGradient(-64, 0, 64, 0);
metal.addColorStop(0, luz ? '#1E2B24' : '#0C1410');
metal.addColorStop(.38, luz ? '#4D6658' : '#2A3D33');
metal.addColorStop(.5, luz ? '#6F8C7C' : '#3A5446');
metal.addColorStop(1, luz ? '#16201B' : '#080D0A');
ctx.fillStyle = metal;
ctx.beginPath();
ctx.moveTo(-64, 60);
ctx.bezierCurveTo(-62, 26, -30, 12, 0, 12);
ctx.bezierCurveTo(30, 12, 62, 26, 64, 60);
ctx.closePath();
ctx.fill();
// Borde inferior con un brillo
ctx.strokeStyle = luz ? 'rgba(255,255,255,.35)' : 'rgba(0,255,127,.12)';
ctx.lineWidth = 1.5;
ctx.beginPath(); ctx.moveTo(-63, 60); ctx.lineTo(63, 60); ctx.stroke();
// Interior de la pantalla
ctx.fillStyle = intensidad > .05 ? `rgba(255, 246, 214, ${.35 + intensidad * .65})` : '#050806';
ctx.beginPath(); ctx.ellipse(0, 60, 62, 6, 0, 0, Math.PI); ctx.fill();
// Bombilla
if (intensidad > .05) { ctx.shadowColor = 'rgba(255, 244, 200, 1)'; ctx.shadowBlur = 50 * intensidad; }
const vidrio = ctx.createRadialGradient(-4, 62, 2, 0, 66, 14);
if (intensidad > .05) { vidrio.addColorStop(0, '#FFFFFF'); vidrio.addColorStop(1, `rgba(255, 238, 190, ${.6 + intensidad * .4})`); }
else { vidrio.addColorStop(0, '#3A4A42'); vidrio.addColorStop(1, '#141E19'); }
ctx.fillStyle = vidrio;
ctx.beginPath(); ctx.arc(0, 66, 13, 0, Math.PI * 2); ctx.fill();
ctx.restore();
// Cadena de bolitas metálicas
for (let i = 1; i < N - 1; i++) {
const A = p[i], B = p[i + 1];
ctx.strokeStyle = luz ? '#7A8780' : '#3F4D45';
ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(A.x, A.y); ctx.lineTo(B.x, B.y); ctx.stroke();
}
for (let i = 0; i < N - 1; i++) {
const q = p[i];
const bola = ctx.createRadialGradient(q.x - 1, q.y - 1, .3, q.x, q.y, 3.2);
bola.addColorStop(0, luz ? '#FFFFFF' : '#C9D6CF');
bola.addColorStop(.45, luz ? '#9AA7A0' : '#6C7B73');
bola.addColorStop(1, luz ? '#4F5C55' : '#2B3630');
ctx.fillStyle = bola;
ctx.beginPath(); ctx.arc(q.x, q.y, 3, 0, Math.PI * 2); ctx.fill();
}
// La gota del final: de cristal verde, orientada hacia donde tira la cadena
const A = p[N - 2], U = p[N - 1];
const giro = Math.atan2(U.y - A.y, U.x - A.x) - Math.PI / 2;
const R = agarrado ? 15 : 13.5;
ctx.save();
ctx.translate(U.x, U.y);
ctx.rotate(giro);
const verde = luz ? '#00873F' : '#00FF7F';
const pulso = luz ? 0 : (quieto ? 14 : 12 + Math.sin(t / 380) * 8);
ctx.shadowColor = verde; ctx.shadowBlur = agarrado ? 26 : pulso;
const cuerpo = ctx.createRadialGradient(-R * .35, R * .9, 1, 0, R * 1.3, R * 1.4);
cuerpo.addColorStop(0, luz ? '#3FD08A' : '#B6FFD8');
cuerpo.addColorStop(.35, verde);
cuerpo.addColorStop(1, luz ? '#00592A' : '#00A352');
ctx.fillStyle = cuerpo;
ctx.beginPath();
ctx.moveTo(0, -R * .35);
ctx.bezierCurveTo(R * .25, R * .15, R, R * .6, R, R * 1.35);
ctx.arc(0, R * 1.35, R, 0, Math.PI);
ctx.bezierCurveTo(-R, R * .6, -R * .25, R * .15, 0, -R * .35);
ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = 'rgba(255, 255, 255, .55)';
ctx.beginPath(); ctx.ellipse(-R * .38, R * 1.05, R * .18, R * .34, .5, 0, Math.PI * 2); ctx.fill();
ctx.restore();
// Pista «tira ↓» junto a la gota, solo hasta el primer tirón
pista.style.transform = `translate(${U.x + 22}px, ${U.y + 4}px)`;
pista.classList.toggle('ver', nuncaTirado && t - ultimoToque > 2500 && !agarrado);
}
function bucle(t) { fisica(t); dibujar(t); requestAnimationFrame(bucle); }
// ---------- Sonido del interruptor, generado al momento (sin archivos) ----------
let audio = null, conSonido = true;
function sonar(fuerte) {
if (!conSonido) return;
try {
audio = audio || new (window.AudioContext || window.webkitAudioContext)();
const n = Math.floor(audio.sampleRate * .028);
const buf = audio.createBuffer(1, n, audio.sampleRate), d = buf.getChannelData(0);
for (let i = 0; i < n; i++) d[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / n, 7);
const src = audio.createBufferSource(); src.buffer = buf;
const filtro = audio.createBiquadFilter(); filtro.type = 'bandpass'; filtro.frequency.value = fuerte ? 2600 : 1500; filtro.Q.value = 1.8;
const vol = audio.createGain(); vol.gain.value = fuerte ? .9 : .45;
src.connect(filtro).connect(vol).connect(audio.destination);
src.start();
} catch (e) { /* sin audio, sin problema */ }
}
// ---------- Cambiar la luz ----------
function cambiarLuz() {
encendida = !encendida;
if (encendida) encendidaEn = performance.now();
const b = mundo(...BOMBILLA);
raiz.style.setProperty('--vx', b.x + 'px');
raiz.style.setProperty('--vy', b.y + 'px');
const aplicar = () => {
raiz.classList.toggle('luz', encendida);
botonLuz.setAttribute('aria-pressed', encendida);
botonLuz.textContent = encendida ? 'Apagar la luz' : 'Encender la luz';
};
if (!document.startViewTransition || quieto) { aplicar(); return; }
raiz.classList.toggle('encendiendo', encendida);
raiz.classList.toggle('apagando', !encendida);
const vt = document.startViewTransition(aplicar);
vt.ready.catch(() => {}); // si el navegador la cancela, el tema ya está cambiado igual
vt.finished.finally(() => raiz.classList.remove('encendiendo', 'apagando'));
}
function soltar() {
agarrado = false;
if (armado) {
armado = false;
nuncaTirado = false;
sonar(false);
cambiarLuz();
}
}
// ---------- Ratón y dedo ----------
const cercaDeGota = (x, y) => { const u = p[N - 1]; return Math.hypot(x - u.x, y - (u.y + 16)) < 36; };
const cercaDeLampara = (x, y) => { const c = mundo(0, 40); return Math.hypot(x - c.x, y - c.y) < 66; };
lienzo.addEventListener('pointerdown', e => {
ultimoToque = performance.now();
puntero = { x: e.clientX, y: e.clientY };
if (cercaDeGota(e.clientX, e.clientY)) {
agarrado = true; movido = 0; inicio = { x: e.clientX, y: e.clientY };
} else if (cercaDeLampara(e.clientX, e.clientY)) {
agarradaLampara = true;
} else return;
lienzo.setPointerCapture(e.pointerId);
});
lienzo.addEventListener('pointermove', e => {
puntero = { x: e.clientX, y: e.clientY };
if (agarrado) movido = Math.max(movido, Math.hypot(e.clientX - inicio.x, e.clientY - inicio.y));
lienzo.style.cursor = agarrado || agarradaLampara ? 'grabbing'
: cercaDeGota(e.clientX, e.clientY) || cercaDeLampara(e.clientX, e.clientY) ? 'grab' : '';
});
const fin = () => {
ultimoToque = performance.now();
if (agarradaLampara) { agarradaLampara = false; return; }
if (!agarrado) return;
if (movido < 8) { agarrado = false; tirando = 14; } // un toque corto: tirón automático
else soltar();
};
lienzo.addEventListener('pointerup', fin);
lienzo.addEventListener('pointercancel', () => { agarrado = false; agarradaLampara = false; armado = false; });
botonLuz.addEventListener('click', () => { if (!tirando) { tirando = 14; ultimoToque = performance.now(); } });
botonSonido.addEventListener('click', () => {
conSonido = !conSonido;
botonSonido.setAttribute('aria-pressed', conSonido);
botonSonido.textContent = 'Sonido: ' + (conSonido ? 'sí' : 'no');
});
addEventListener('resize', medir);
medir();
requestAnimationFrame(bucle);
})();
▶
Explicado paso a paso en el episodio
5 efectos web que tus clientes no han visto nunca (el nº1 enciende la luz)
8:54La cuerda de la luz