Build Apple-Inspired Full Page Scrolling Pages For Your WordPress Site

That full page scrolling is becoming increasingly popular is hardly surprising as it taps into our paper-based reading experiences and provides all the visual clues about needing to read to the end before “turning the page”.

In this post, I’ll show you how to leverage all the advantages of full page scrolling in your WordPress site by integrating the fullPage.js library – the gold standard of full page scrolling – to build an Apple-inspired, full page, scrolling landing page with animation.

5 Apple iPhone 5Cs with the title Apple fullPage.js Demo
Build impressive pages with animation and full page scrolling

This post was inspired by the examples that Alvaro Trigo has put together to showcase his fullPage.js jQuery plugin which delivers full page scrolling both vertically and horizontally. In particular, the clone of the now-superseded promotional page for Apple’s iPhone 5C is particularly impressive, combining full page scrolling and animation.

Have a look at the demo as this is what we are going to recreate in WordPress. To do this, we’ll need to:

  1. Create a template specifically for using fullPage.js
  2. Ensure that any post that uses fullPage.js is rendered using the new template
  3. Mark-up post content so that it is fullPage.js compatible
  4. Add custom post-specific CSS for injecting into the output
  5. Add custom post-specific javascript for injecting into the output to initialize fullPage.js

Steps 2 to 5 are facilitated via a custom plugin. There is a WP FullPage plugin in the WordPress.org plugin repository but I have to confess that I had a hard time using it, so I resorted to writing my own, much simpler version.

Step 1 – Creating A Specific fullPage.js Template

As fullPage.js is, as the name suggests, full page, it needs to operate in as simple a template as possible, devoid of any headers, footers and sidebars that your current theme may have.

And that requires a custom template.

The plugin comes with a simple template (see /templates/fullpage.php), designed to let fullPage.js be completely unencumbered as it does its work:

As you can see, there’s really not much to it. It outputs the standard CSS, the jQuery plugin (both contained in the plugin’s directories) and jQuery itself as well as any custom CSS (this is held in the post’s fullpage_css custom field).

jQuery and jQuery UI are pulled in from the Google CDN, so change this if you prefer to use a local copy.

The only actual content is the post’s filtered content but you’ll notice that we first remove the wpautop filter from the the_content function so that we can better lay out the content without having to worry about superfluous <p> tags being added that can easily break your content.

The final action of the script is to output the javascript to initiate fullPage.js on the page itself. If the post has the fullpage_js custom field set then this content is used as the initialization script otherwise the default fullPage.js initialization script is used.

Step 2 – Ensure the New Template Is Used

It’s no good having a template unless it gets used of course, so the plugin that adds fullPage.js to your WordPress install, uses the template_include filter to change the template if the post is using fullPage.js.

The fullpage template is located in the plugin’s /templates folder.

Download, install and activate the plugin.

Step 3 – Mark-up fullPage.js Compatible Post Content

When porting the example across to WordPress, there were a number of decisions to be made about how much functionality should be abstracted.

To keep things initially simple, I’ve opted for (only!) 5 new shortcodes to model fullPage.js‘s basic structure:

  1. fullpage – this is the main container for a fullPage.js page; all content should reside inside this wrapper
  2. section – a section is effectively a page; has the following attributes:
    • id – adds an id which can be referenced in CSS or javascript
    • action – is currently translated to a class
  3. slide – similar to section in that it is a page but is intended for horizontal scrolling; should always be contained within a section; has the following attributes: 
    • bg – the url of an image to be used as the background image
  4. header – a fixed bar at the top of the page
  5. footer – a fixed bar at the bottom of the page

So, a basic fullPage.js structure would look something like this (in text mode):

{code}
[fullpage]

[header]Header[/header]

[section id=”section1″]
This is slide 1
This is slide 2
This is slide 3
[/section]

[section id=”section2″]
<h2>Section 2</h2>
<p>This is section two!</p>
[/section]

[footer]Footer[/footer]

[/fullpage]
{/code}

In the Apple example, this means that quite a bit of the mark-up is left as <div> tags.

Here’s the content marked-up with the shortcodes and the <div>s:

Step 4 – Add Post-specific CSS

One of the enormous benefits of fullPage.js is just how flexible it is and I wanted an implementation that didn’t restrict that flexibility at all.

So, I’ve left the adding of custom CSS to a textarea in a new post edit screen metabox created by the custom plugin.

Screengrab of the post edit screen showing the new metabox
A new metabox on the post edit screen allows full control over styling and initialization

This CSS is for custom styling only – there’s no need to define the structure of a section or slide, this is done in the standard CSS file

The post-specific CSS for the Apple demo is:

It’s pretty comprehensive and all the sections are styled beyond the standard styling. Of particular interest is the treatment of the #staticImg element. This is actually the green iPhone that slides from section 3 to 4 on scroll; this animation is controlled via the toggling of the moveDown and moveUp clauses.

Step 5 – Add Post-specific Javascript

I did think long and hard about whether I could abstract out the javascript to make it easier. WP FullPage does do this but I’m not sure how much time and effort it saves, so instead there’s a second textarea in the fullPage.js metabox that allows the inputting of the fullPage.js initialization script.

If you leave this empty then the standard script will be used but in this case the Apple demo requires a little more interaction:

The script is an initialization of fullpage (the #fullpage id is automatically added when processing the [fullpage] shortcode) and consists of setting properties and specifying functions to call on fullPage.js custom events.

The 2 custom events used here are afterLoad and onLeave and refer to the displaying of a section. The events are used to trigger functions that toggle classes on various elements in order to trigger an animation.

For example, in the afterLoad function, if the index is 2 (that is the second section is being displayed) the images in the section have the active class added (these trigger the horizontal slide-ins).

Step 6 – Finalizing And Running The Demo

Before you can view the final demo, you’ll need to insert the images into your post. I’ve included them in the plugin’s folders, so locate that folder and do a batch upload.

You’ll need to change the filenames in the content to match your installation.

Once the images are loaded, you are good to go. If you view the post, you should be looking at something similar to this:

The Apple iPhone 5C line-up with the title Apple fullPage.js Demo
The first section in the impressive Apple demo

On a desktop use the mouse scroll-wheel to navigate the sections, on a tablet swipe up and down (although be aware that the demo is not really designed for a tablet).

Tip Of The Iceberg

This is an impressive demo but, of course, all the hard work had already been done by Alvaro; all we had to do was make it WordPress-friendly.

That said, the basics of sections and slides should work out of the box, so you have the beginnings of a really very powerful tool for building some impressive landing pages, especially when those CSS3 transition muscles are flexed.

It would be a waste, however, to restrict fullPage.js to just landing pages. Alvaro’s additional examples such as the One Single Section (a full page slider sitting above normal website content) should fire up plenty of curiosity and it’s not hard to see fullPage.js being used to deliver a wide range of fullpage scrolling content that is at home both on the desktop or mobile devices.

I’ve included the Apple, One Single Section and Vertical Navigation Dots examples in the plugin’s /content folder, so have a play with this awesome library. Yes, there can be quite a bit of hand-coding involved but the results are definitely worth it.

What’s really required, is a little imagination.