All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Minimal HTML Slideshow Implementation in 22 Lines of JavaScript

By

Curiositry

6mo ago· 1 min readen

Summary

The article presents a minimal HTML slideshow implementation using only 22 lines of JavaScript (371 bytes). It demonstrates how to create a functional slideshow with navigation controls (j/k keys for slide movement, 'n' for notes toggle) and includes BroadcastChannel for cross-tab synchronization. The code shows how to efficiently select slide elements and their associated notes, with smooth scrolling between slides.

Key quotes

· 4 pulled
HTML Slides with notes ... in 22 lines, or 371 bytes of JavaScript
let a=[...document.getElementsByClassName('slide')].map((a,b)=>[a,'slidenote'==(b=a.nextElementSibling)?.className?b:a]),b=0,c=0,d=()=>a[b][c].scrollIntoView()
e.onmessage=({data:a})=>{c^=a.c,b=a.b,d()};document.addEventListener('keypress',({key:f})=>{b+=(f=='j')-(f=='k');b=b<0?0:b>l?l:b;c^=f=='n';e.postMessage({c,b});d()})
... but not before pointing out that this really minifies to super-tiny code - and still
Snippet from the RSS feed
Don't worry, I'll walk you all through it in a readable font size!

You might also wanna read