slideswap
A cross-fade slideshow for slides that are not the same size — a paragraph, then a portrait image, then a wide one.
- Slides stack at
opacity: 0and only the current one occupies space, so nothing has to be forced into a fixed frame. - The container animates its height to the incoming slide, and measures again when a lazy image finishes loading — a late image does not leave the box the wrong size.
- Timing lives in CSS. The script reads
transition-durationback off the element and schedules against it, so the fade is a stylesheet edit rather than an option. - Swipe is built in, along with the grab cursor and the text selection it would otherwise drag.
- Slides that are not showing take
aria-hiddenandtabindex="-1", so a screen reader and the tab order see only the visible one.
Where that stops: there are no roles and no arrow-key navigation, so this is not the APG carousel pattern.
Demo
Adding and removing slides
add(slide) appends and remove() drops the last one — both take an
optional index for a specific position. add() leaves you on the slide you were
already on, so Add below follows it with setCurrentSlide(); without that the
new slide sits at opacity: 0 and the button looks like it did nothing.
Installation
Install via npm:
npm install slideswap