I had a client that needed a really light-weight implementation of multi-page blog posts that refreshed the page. Due to time constraints, we couldn't build a plugin for the CMS (Movable Type) and it was a requirement to use static pages. This left doing something in JavaScript, which is fine because it's not difficult to make it accessible and easy for a writer to use.
The two requirements for this implementation are JQuery and JQuery Query (which could be replaced with straight JS, but this was quicker and easier). The rest is straight HTML and CSS.
- In order to create a new page in your article add
<!-- PAGE BREAK -->
in your code wherever you'd like a new page to begin. - Passing
?page=n
to the querystring of the URL will let you select a particular page. - If the page is unrecognized or the user passes a non-number, it will show page 1. The one exception is the value "all", which will show the content of all the pages.
- One note: I recommend setting the
.entry-body
element todisplay: none;
in your CSS. That way the user won't see the text change from everything to just a small part of it. It means they'll see nothing for a second, but I've tried to do everything I can to keep that time to a minimum.
That's it! If you want to try out the file below, you'll need to have JQuery Query in the same directory as the HTML file.