New releases

Hotwire Club tooling is now open-source

Explore the agentic skills pack and the MCP server for building assistant workflows.

Turbo Frames - Swiper with Autoplay and View Transitions

Create an autoplaying swiper using view transitions and Turbo Frames

View Solution on Patreon
Turbo Frames - Swiper with Autoplay and View Transitions

Premise

In Challenge 38, we employed view transitions to spice up regular page navigation when browsing an image gallery. This time we’ll use the same technique to drive an autoplaying swiper embedded in a Turbo Frame.

Starting Point

First of all, there’s a single Turbo Frame in our layout, that points to a route returning a slide containing an image (/slide/:id):

https://stackblitz.com/edit/turbo-frames-swiper?file=index.html%3AL41

I’ve crafted a background service returning this slide. The crucial point is that the <article> it includes already contains a reference to the next slide in form of a data attribute, like so: <article data-next="1001">. Essentially, this loops over the following array:

const slideIds = [1000, 1001, 1002, 1011];

https://stackblitz.com/edit/turbo-frames-swiper?file=index.js%3AL24

Furthermore, view-transitions.css is a stripped down version of the one we used in Challenge 38:

https://stackblitz.com/edit/turbo-frames-swiper?file=view-transitions.css

Finally, the “autoplay” feature is implemented using a simple setTimeout that’s triggered upon turbo:frame-load:

document
  .querySelector('#swiper')
  .addEventListener('turbo:frame-load', (event) => {
    setTimeout(() => {
      const nextId = event.target.querySelector('article').dataset.next;

      event.target.src = `/slide/${nextId}`;
    }, 5000);
  });

https://stackblitz.com/edit/turbo-frames-swiper?file=app.js%3AL9

Challenge

To enable view transitions we have to create a custom render function like in Challenge 2. Because Turbo Frames aren’t full browser documents, you have to use document.startViewTransition to manually trigger it:

Here’s a look at the result:

Images being animated in and out of a Turbo Frame

This is The Hotwire Club

46 hands-on challenges with detailed solutions, published biweekly since 2023. Subscribe to access all solutions and join the Discord community.

Subscribe on Patreon

More from

Turbo Frames - Form Submission Loading States
10 March 2026

Add loading feedback to form submissions inside Turbo Frames using busy attributes and data-turbo-submits-with.

Turbo Frames - Using External Forms
03 February 2026

Refer to external forms from within a Turbo Frame

Turbo Frames - Loading Spinner
20 January 2026

Display a loading spinner while a Turbo Frame is `busy` fetching content asynchronously

Cookies
essential