Controlling stories slides with code

By default, Flourish stories include captions and buttons that let users move forward and back, through the slides. But in some cases, you might want to create a completely different kind of navigation, like a multi-button menu or a “scrollytelling” story, in which the user scrolls down a page to navigate through the story. This can be done with JavaScript by anyone with web development skills.

For an example: Check out this Sky News piece on vaccines and our blog post on how they did it.

While it's possible to achieve this with JavaScript from scratch, we also offer a no-code solution via our own scrollytelling library which is available exclusively to our Enterprise customers. Get in touch with our sales team if you’re interested in getting scrollytelling on your own site.

How Flourish story URLs work

Below is a story with five slides. When you embed a Flourish story, the embed code creates an iframe pointing at a URL that looks like this:

The hash on the end of the URL ( #slide-0) shows the zero-index of the current slide, with "0" being the first slide, :1" the second slide, etc. Changing this hash with code will switch the slide. Here’s a simple interactive example:

The code for this example is as follows:

var input = document.querySelector("#my-input");
input.addEventListener("change", function(e) {
	var iframe = document.querySelector("#my-story iframe");
	iframe.src = iframe.src.replace(/#slide-.*/, "") + "#slide-" +;

How to use Flourish stories for scrollytelling

There are different ways to convert normal Flourish stories into scrollytelling stories, but the basic idea is that you need to create a scroll event or intersection observer on your page that looks for certain “triggers” (e.g. text blocks) that then change the slide (i.e. hash) in the Flourish story when they reach the the middle of the screen. Various libraries make this easy to do, but we recommend Scrollama.