{"id":131886,"date":"2014-09-18T08:00:00","date_gmt":"2014-09-18T12:00:00","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=131886"},"modified":"2014-09-18T02:55:50","modified_gmt":"2014-09-18T06:55:50","slug":"build-apple-inspired-full-page-scrolling-pages-for-your-wordpress-site","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/build-apple-inspired-full-page-scrolling-pages-for-your-wordpress-site\/","title":{"rendered":"Build Apple-Inspired Full Page Scrolling Pages For Your WordPress Site"},"content":{"rendered":"<p>That full page scrolling is\u00a0becoming increasingly popular\u00a0is hardly\u00a0surprising as it taps into our paper-based reading experiences and provides\u00a0all the visual clues about needing to read to the end before &#8220;turning the page&#8221;.<\/p>\n<p>In this post, I&#8217;ll show you how to leverage all the advantages of full page scrolling in your WordPress site by integrating the fullPage.js library &#8211; the gold standard of full page scrolling &#8211; to build an Apple-inspired, full page, scrolling landing page with animation.<\/p>\n<figure id=\"attachment_132191\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-132191\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/09\/fullpage-featured-700x326.jpg\" alt=\"5 Apple iPhone 5Cs with the title Apple fullPage.js Demo\" width=\"700\" height=\"326\" \/><figcaption class=\"wp-caption-text\">Build impressive pages with animation and full page scrolling<\/figcaption><\/figure>\n<p>This post was inspired by the examples that <a title=\"Visit Alvaro's website\" href=\"http:\/\/alvarotrigo.com\/\" rel=\"noopener\" target=\"_blank\">Alvaro Trigo<\/a>\u00a0has put together to showcase his <a title=\"Read more about this plugin on GitHub\" href=\"https:\/\/github.com\/alvarotrigo\/fullPage.js\" rel=\"noopener\" target=\"_blank\">fullPage.js jQuery plugin<\/a> which\u00a0delivers\u00a0full page scrolling both vertically and horizontally. In particular, the <a title=\"View this and other fullPage.js examples\" href=\"http:\/\/alvarotrigo.com\/fullPage\/examples\/apple.html\" rel=\"noopener\" target=\"_blank\">clone of the now-superseded promotional page for Apple&#8217;s iPhone 5C<\/a> is particularly impressive, combining full page scrolling and animation.<\/p>\n<p>Have a look at the demo as this is what we are going to recreate in WordPress. To do this, we&#8217;ll need to:<\/p>\n<ol>\n<li>Create a <em>template<\/em> specifically for using <em>fullPage.js<\/em><\/li>\n<li>Ensure that any post that uses <em>fullPage.js<\/em> is rendered using the new template<\/li>\n<li>Mark-up post content so that it is <em>fullPage.js<\/em> compatible<\/li>\n<li>Add\u00a0custom post-specific CSS for\u00a0injecting into the output<\/li>\n<li>Add custom post-specific javascript for injecting\u00a0into the output to initialize <em>fullPage.js<\/em><\/li>\n<\/ol>\n<p>Steps 2 to 5\u00a0are facilitated via a custom plugin. There is a <a title=\"Read more about this plugin in the WordPress plugin repository\" href=\"https:\/\/wordpress.org\/plugins\/wp-fullpage\/\" rel=\"noopener\" target=\"_blank\">WP FullPage plugin<\/a> 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.<\/p>\n<h2>Step 1 &#8211; Creating A Specific fullPage.js Template<\/h2>\n<p>As <em>fullPage.js<\/em> 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.<\/p>\n<p>And that requires a custom template.<\/p>\n<p>The plugin comes with a simple template (see \/templates\/fullpage.php), designed to let <em>fullPage.js<\/em> be completely unencumbered as it does its work:<\/p>\n<div class=\"gist\" data-gist=\"ad4397db80c95570fe4e\" data-gist-file=\"fullpage_template.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ad4397db80c95570fe4e.js?file=fullpage_template.php\">Loading gist ad4397db80c95570fe4e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>As you can see, there&#8217;s really not much to it. It outputs the standard CSS, the jQuery plugin (both contained in the plugin&#8217;s directories) and jQuery itself as well as any custom CSS (this is held in the post&#8217;s fullpage_css custom field).<\/p>\n<p>jQuery and jQuery UI are pulled in from the Google CDN, so change this if you prefer to use a local copy.<\/p>\n<p>The only actual content is the post&#8217;s filtered content but you&#8217;ll notice that we first remove the <a title=\"Read more about this function on the WordPress Codex\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wpautop\" rel=\"noopener\" target=\"_blank\">wpautop<\/a> filter\u00a0from the <a title=\"Read more about this function on the WordPress Codex\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/the_content\" rel=\"noopener\" target=\"_blank\">the_content<\/a> function so that we can better lay out the content without having to worry about superfluous <em>&lt;p&gt;<\/em> tags being added that can easily break your content.<\/p>\n<p>The final action of the script is to output the javascript to initiate <em>fullPage.js<\/em> on the page itself. If the post has the\u00a0<em>fullpage_js<\/em> custom field set then this content is used as the initialization script otherwise the default <em>fullPage.js<\/em> initialization script is used.<\/p>\n<h2>Step 2 &#8211; Ensure the New Template Is Used<\/h2>\n<p>It&#8217;s no\u00a0good having a template unless it gets used of course, so the plugin that adds <em>fullPage.js<\/em> to your WordPress install, uses the <a title=\"Read more about this filter on the WordPress Codex\" href=\"http:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/template_include\" rel=\"noopener\" target=\"_blank\">template_include<\/a> filter to change the template if the post is using <em>fullPage.js<\/em>.<\/p>\n<div class=\"gist\" data-gist=\"ad4397db80c95570fe4e\" data-gist-file=\"fullpage_template_include.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ad4397db80c95570fe4e.js?file=fullpage_template_include.php\">Loading gist ad4397db80c95570fe4e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>The <em>fullpage<\/em> template is located in the plugin&#8217;s <em>\/templates<\/em> folder.<\/p>\n<p>Download, install and activate the plugin.<\/p>\n<h2>Step 3 &#8211; Mark-up fullPage.js Compatible Post Content<\/h2>\n<p>When porting the example across to WordPress, there were a number of decisions to be made about how much functionality should be abstracted.<\/p>\n<p>To keep things initially simple, I&#8217;ve opted for (only!) 5\u00a0new shortcodes to model <em>fullPage.js<\/em>&#8216;s basic structure:<\/p>\n<ol>\n<li><em>fullpage &#8211; <\/em>this is the main container\u00a0for a fullPage.js page; all content should reside inside this wrapper<\/li>\n<li><em>section &#8211; <\/em>a section is effectively a page; has the following attributes:\n<ul>\n<li>id &#8211; adds an id which can be referenced in CSS or javascript<\/li>\n<li>action &#8211; is currently translated to a class<\/li>\n<\/ul>\n<\/li>\n<li><em>slide &#8211; <\/em>similar to section in that it is a page but is intended for horizontal scrolling; should always be contained within a <em>section;<\/em> has the following attributes:<em>\u00a0<\/em>\n<ul>\n<li>bg &#8211; the url of an image to be used as the background image<\/li>\n<\/ul>\n<\/li>\n<li><em>header<\/em>\u00a0&#8211; a fixed bar at the top of the page<\/li>\n<li><em>footer &#8211; <\/em>a fixed bar at the bottom of the page<\/li>\n<\/ol>\n<p>So, a basic fullPage.js structure would look something like this (in text mode):<\/p>\n<p><code><br \/>\n[fullpage]<\/code><\/p>\n<p>[header]Header[\/header]<\/p>\n<p>[section id=&#8221;section1&#8243;]<br \/>\n[slide id=&#8221;slide1&#8243;]This is slide 1[\/slide]<br \/>\n[slide id=&#8221;slide2&#8243;]This is slide 2[\/slide]<br \/>\n[slide id=&#8221;slide3&#8243;]This is slide 3[\/slide]<br \/>\n[\/section]<\/p>\n<p>[section id=&#8221;section2&#8243;]<br \/>\n&lt;h2&gt;Section 2&lt;\/h2&gt;<br \/>\n&lt;p&gt;This is section two!&lt;\/p&gt;<br \/>\n[\/section]<\/p>\n<p>[footer]Footer[\/footer]<\/p>\n<p>[\/fullpage]<\/p>\n<p>In the Apple example, this means that quite a bit of the mark-up is left as <em>&lt;div&gt;<\/em> tags.<\/p>\n<p>Here&#8217;s the content marked-up with the shortcodes and the<em> &lt;div&gt;<\/em>s:<\/p>\n<div class=\"gist\" data-gist=\"ad4397db80c95570fe4e\" data-gist-file=\"fullpage_markup_apple.html\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ad4397db80c95570fe4e.js?file=fullpage_markup_apple.html\">Loading gist ad4397db80c95570fe4e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h2>Step 4 &#8211; Add Post-specific CSS<\/h2>\n<p>One of the enormous benefits of <em>fullPage.js<\/em> is just how flexible it is and I wanted an implementation that didn&#8217;t restrict that flexibility at all.<\/p>\n<p>So, I&#8217;ve left the adding of custom CSS to a textarea in a new post edit screen metabox\u00a0created by the custom plugin.<\/p>\n<figure id=\"attachment_132202\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-132202\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/09\/fullpage-metabox.png\" alt=\"Screengrab of the post edit screen showing the new metabox\" width=\"700\" height=\"361\" \/><figcaption class=\"wp-caption-text\">A new metabox on the post edit screen allows full control over styling and initialization<\/figcaption><\/figure>\n<p>This CSS is for custom styling only &#8211; there&#8217;s no need to define the structure of a section or slide, this is done in the standard CSS file<\/p>\n<p>The post-specific CSS for the Apple demo is:<\/p>\n<div class=\"gist\" data-gist=\"ad4397db80c95570fe4e\" data-gist-file=\"fullpage_apple.css\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ad4397db80c95570fe4e.js?file=fullpage_apple.css\">Loading gist ad4397db80c95570fe4e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>It&#8217;s pretty comprehensive and all the sections are styled beyond the standard styling. Of particular interest is the treatment of the #<em>staticImg<\/em> 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 <em>moveDown<\/em> and <em>moveUp<\/em> clauses.<\/p>\n<h2>Step 5 &#8211; Add Post-specific Javascript<\/h2>\n<p>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&#8217;m not sure how much time and effort it saves, so instead there&#8217;s a second textarea in the <em>fullPage.js<\/em> metabox that allows the inputting of the <em>fullPage.js<\/em> initialization script.<\/p>\n<p>If you leave this empty then the standard script will be used but in this case the Apple demo\u00a0requires a little more interaction:<\/p>\n<div class=\"gist\" data-gist=\"ad4397db80c95570fe4e\" data-gist-file=\"fullpage_apple.js\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ad4397db80c95570fe4e.js?file=fullpage_apple.js\">Loading gist ad4397db80c95570fe4e<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>The script is an initialization of fullpage (the #<em>fullpage<\/em> id is automatically added when processing the [<em>fullpage<\/em>] shortcode) and consists of setting properties and specifying functions to call on <em>fullPage.js<\/em> custom events.<\/p>\n<p>The 2 custom events used here are <em>afterLoad<\/em> and <em>onLeave<\/em> 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.<\/p>\n<p>For example, in the <em>afterLoad<\/em> function, if the <em>index<\/em> is 2 (that is the second section is being displayed) the images in the section have the <em>active<\/em> class added (these trigger the horizontal slide-ins).<\/p>\n<h2>Step 6 &#8211; Finalizing And Running The Demo<\/h2>\n<p>Before you can view the final demo, you&#8217;ll need to insert the images into your post. I&#8217;ve included them in the plugin&#8217;s folders, so locate that folder and do a batch upload.<\/p>\n<p>You&#8217;ll need to change the filenames in the content to match your installation.<\/p>\n<p>Once the images are loaded, you are good to go. If you view the post, you should be looking at something similar to this:<\/p>\n<figure id=\"attachment_132203\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-132203\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/09\/fullpage-apple-section1-700x715.jpg\" alt=\"The Apple iPhone 5C line-up with the title Apple fullPage.js Demo\" width=\"700\" height=\"715\" \/><figcaption class=\"wp-caption-text\">The first section in the impressive Apple demo<\/figcaption><\/figure>\n<p>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).<\/p>\n<h2>Tip Of The\u00a0Iceberg<\/h2>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>It would be a waste, however, to restrict fullPage.js to just landing pages.\u00a0Alvaro&#8217;s\u00a0additional examples such as the <a title=\"View this example\" href=\"http:\/\/alvarotrigo.com\/fullPage\/examples\/oneSection.html\" rel=\"noopener\" target=\"_blank\">One Single Section<\/a> (a full page slider sitting above normal website content)\u00a0should fire up plenty of curiosity and it&#8217;s not hard to see <em>fullPage.js<\/em>\u00a0being used to deliver a\u00a0wide range of fullpage scrolling\u00a0content that is at home both on the desktop or mobile devices.<\/p>\n<p>I&#8217;ve included the Apple, One Single Section and Vertical Navigation Dots examples in the plugin&#8217;s <em>\/content<\/em> 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.<\/p>\n<p>What&#8217;s really required, is a little imagination.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>That full page scrolling is\u00a0becoming increasingly popular\u00a0is hardly\u00a0surprising as it taps into our paper-based reading experiences and provides\u00a0all the visual clues about needing to read to the end before &#8220;turning the page&#8221;. In this post, I&#8217;ll show you how to leverage all the advantages of full page scrolling in your WordPress site by integrating the [&hellip;]<\/p>\n","protected":false},"author":262394,"featured_media":132191,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[9957,9825],"tutorials_categories":[],"class_list":["post-131886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-full-page","tag-landing-pages"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/262394"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=131886"}],"version-history":[{"count":2,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131886\/revisions"}],"predecessor-version":[{"id":203911,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131886\/revisions\/203911"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/132191"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=131886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=131886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=131886"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=131886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}