Nikebetterworld Parallax Effect Demo

Post Updates

27th October 2011 - This tutorial has now been turned into a jQuery plugin. Download/fork on GitHub.

12th September 2011 - If you're developing your own JavaScript parallax effects, you may be interested to read my follow up to this post: JavaScript Parallax Effects: A Deeper Look

A couple of months ago, I created a jQuery Vertical Parallax Demo that manipulated CSS to make multiple backgrounds move at different speeds relative to the users movement of the scroll bar. This type of effect is slowly appearing across various websites on the web, achieved using many different techniques. Nikebetterworld took the idea to a new level.

In today’s tutorial, we’re going to take the original jQuery Parallax script I wrote and recreate a webpage similar to Nikebetterworld.

If you’d like to see what we’ll be creating, go check out the demo or download the files.

The HTML

Our page will consist of 6 sections: header, footer and 4 articles. On the right, we’ll place an unordered list that links between the articles and remains fixed on the page so it doesn’t move.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="scripts/nbw-parallax.js"></script>
<script type="text/javascript" src="scripts/jquery.localscroll-1.2.7-min.js"></script>
<script type="text/javascript" src="scripts/jquery.scrollTo-1.4.2-min.js"></script>
<script type="text/javascript" src="scripts/jquery.inview.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#nav').localScroll();
})
</script>

To start, at the top of the page, we’ll reference all of the JavaScript files we’ll use to make the effect work. The scripts we’re using are:

<ul>
    <li><a title="jQuery 1.4.4" href="http://api.jquery.com/category/version/1.4.4/">jQuery 1.4.4</a></li>
    <li>The script I wrote (which we'll cover shortly)</li>
    <li><a title="jQuery localscroll" href="http://www.flesler.blogspot.com/2007/10/jquerylocalscroll-10.html">jQuery localscroll</a> (which smoothly scrolls between articles)</li>
    <li><a title="jQuery scrollTo" href="http://www.flesler.blogspot.com/2007/10/jqueryscrollto.html">jQuery scrollTo</a> (also needed for smooth scrolling)</li>
    <li><a title="jQuery In View" href="http://remysharp.com/2009/01/26/element-in-view-event-plugin/">jQuery Inview</a> (determines whether a particular article is in view)</li>
</ul>

We also need to initiate the localScroll function on the unordered list of article links that are fixed to the right of the page.

<ul id="nav">
    <li><a href="#intro" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
    <li><a href="#second" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
    <li><a href="#third" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
    <li><a href="#fourth" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
    <li><a href="#fifth" title="Next Section"><img src="images/dot.png" alt="Link" /></a></li>
</ul>

Inside of our  body tag, we begin with the unordered list that provides a quick link to each section. Without JavaScript, these links will act as anchors that simply jump to what ever article the user clicks on. With the use of jQuery though, we’ve already set each link up to smoothly scroll to it’s respective article. The smooth scrolling will help showcase the parallax effect we’re about to set up.

<div id="intro">
    <div class="story">
        Article content here
    </div> <!--.story-->
</div> <!--#intro-->

Finally, for our HTML, we have the containers that make up each article.

The CSS

I won’t cover what all of the CSS does, just that which is relevant to the working of the effect. Let’s take a look at the CSS for the HTML container I just mentioned above:

#intro{
    background:url(images/firstBG.jpg) 50% 0 no-repeat fixed;
    color: white;
    height: 600px;
    margin: 0;
    padding: 160px 0 0 0;
}

The first article (#intro), will have one background image and a height of 600px. The width isn’t defined so it will stretch to 100% of the window. Each background image used for the articles I have made 1900px so the majority of monitors will have a full image background. Anything over 1900px will see a white border.

.story{
    margin: 0 auto;
    min-width: 980px;
    width: 980px;
}

Inside of the #intro container, we have .story which is present in every article container. This purely keeps each article centered in the browser and with a width of 980px, almost every monitor will see the website without the need for horizontal scroll bars.

Multiple Backgrounds

Some of the articles have multiple backgrounds. Nikebetterworld achieved this using extra HTML in the article container which is exactly what I’ve done for the “Multiple Backgrounds” article, just like this:

<div id="second">
    <div class="story">
        <div class="bg"></div>
            Article content here
    </div> <!--.story-->
</div> <!--#second-->

The div with the class of “bg” has it’s own background:

#second .bg{
    background: url(images/trainers.png) 50% 0 no-repeat fixed;
    ...
    position: absolute;
    ...
    z-index: 200;
}

This div is also given an absolute position and a high z-index to make sure it appears above everything else.

However, although this is the best way to achieve support across all browsers for multiple backgrounds, it’s also possible to use CSS3 multiple backgrounds, which I demonstrate in the fourth article in the demo “Empty Containers vs CSS3 Multiple Backgrounds”.

Using CSS3 means we don’t have to place empty containers in the markup and leave the styling to CSS which is how things should (and one day will) be. So, let’s look at the CSS for the fourth article container:

#fourth{
    background: url(images/bubbles2.png), url(images/bubbles2.png), url(images/bubbles1.png), url(images/fourthBG.jpg);
    background-position: 50% 0, 50% 0, 50% 0, 50% 0;
    background-color: #036;
    background-attachment: fixed;
    background-repeat: repeat, repeat, repeat ,no-repeat;
}

As you can see, I’ve used CSS3 to give one element multiple backgrounds. I’ve also given each of those backgrounds their own position values. We’ll be manipulating these values in jQuery shortly.

Note: In my original jQuery Parallax Demo, I used shorthand CSS to define all of the backgrounds values which is what I did in this demo to begin with too. However, because I used shorthand, when I started manipulating the background positions via jQuery, it meant not only were the background positions being changed, but so too were the background urls and this made the jQuery very heavy. Infact, only Chrome is able to cope with running that original script smoothly at this time, but I do plan to take what I’ve learnt in this demo and optimize the code in the hope it will run smoothly across all browsers too.

So, it is entirely up to you which method you use to create multiple backgrounds. Extra markup means the effect will work across all browsers but if you’re just trying this demo for fun, I recommend CSS3 because you can achieve much more with it.

The jQuery

Now we get to the meat of this tutorial! First thing’s first, optimization! As mentioned above, my original jQuery Parallax Demo was quite a difficult script for browsers to deal with because it was asking them to do a lot. This script is much lighter thanks to the above mentioned CSS along with a good amount of jQuery optimization:

var $window = $(window);
var $firstBG = $('#intro');
var $secondBG = $('#second');
var $thirdBG = $('#third');
var $fourthBG = $('#fourth');
var trainers = $("#second .bg");

We start by turning our selectors into variables for referencing in the script later on.

We will need the height of the browser window on a few occasions so we’ll put that into a variable too:

var windowHeight = $window.height();

Next up, comes our ‘inview’ event which uses thejQuery Element in view Event Plugin:

$('#intro, #second, #third, #fourth').bind('inview', function (event, visible) {
    if (visible == true) {
        $(this).addClass("inview");
    }else{
      $(this).removeClass("inview");
    }
});

I’m using this plugin for optimisation reasons too. Quite simply, it determines whether a particular element is ‘in view’ or not. I’ve coded it so that if one of the articles is ‘in view’, then it applies a class of “inview” to that article. Later on in the script, we run an “if statement” to determine whether an article is ‘in view’ before manipulating the position of it’s background image. By doing this, it means only the background images the user can see will be moved, thus saving the script from moving all background images at the same time.

Next, we have three functions which will be called at three separate occasions. Firstly, the positioning of the unordered list I mentioned, that is fixed to the right of the window:

function RepositionNav(){
    var windowHeight = $window.height();
    var navHeight = $('#nav').height() / 2;
    var windowCenter = (windowHeight / 2);
    var newtop = windowCenter - navHeight;
    $('#nav').css({"top": newtop});
}

We want the unordered list to always remain vertically in the centre of the browser window. The code above takes the height of the list and divides it by two to find it’s centre. Then it finds the centre of the window in the same way. It subtracts one value from the other to find the new top position of the unordered list and finally applies it.

Our second function is where the magic happens. It’s the little bit of code that works out how to move each background image respective to the position of the scrollbar:

function newPos(x, windowHeight, pos, adjuster, inertia){ return x + “% ” + (-((windowHeight + pos) – adjuster) * inertia) + “px”; }

When we call the function further in the script, we’ll provide it five different arguments, which are much like settings that make each call to that function unique. They are as follows:

  • x = the horizontal position of the image
  • windowHeight = the height of the window
  • pos = The position of the scrollbar
  • adjuster = A value that moves the background image into a position we want
  • inertia = The speed at which the background image moves in relation to the scrollbar

The function then uses these arguments we’ve fed it to return one property that changes the CSS property, ‘background-position’ of whichever article we request. An example output would be:

50% -400px

That value is yet to be applied though. That’s where our final function comes in.

function Move(){
    var pos = $window.scrollTop();
    ...
}

Move() is to be called whenever the user moves the scrollbar window or resizes the browser. It starts by working out the position of the scrollbar.

Then, we have several “if statements” that check to see if an article is “in view”:

if($firstBG.hasClass("inview")){
    $firstBG.css({'backgroundPosition': newPos(50, windowHeight, pos, 900, 0.3)});
}

In this “if statement”, we check to see if the first article has the class of “inview”. Remember, our “in view” check earlier on applied this class for us. If the article is “in view”, we change the CSS property, ‘backgroundPosition’ using the newPos function as explained above.

The function continues to test if each article has the class of “inview” and if so, it changes the “backgroundPosition” property.

You will notice in this demo, the second article has two lines of code that each change a different “backgroundPosition”. One is for the full background of the second article, the other changes the background of the extra bit of markup:

<div class="bg"></div>

As I mentioned, in the fourth article I used CSS3 multiple backgrounds so when the function tests the fourth article to see if it has the class of “inview” and it does, the following code is used:

$fourthBG.css({'backgroundPosition': newPos(0, windowHeight, pos, 200, 0.9) + ", " + newPos(50, windowHeight, pos, 0, 0.7) + ", " + newPos(50, windowHeight, pos, 0, 0.5) + ", " + newPos(50, windowHeight, pos, 700, 0.3)});

The newPos function is simply called multiple times to work out the position of each background image.

One final piece of code for this function:

$('#pixels').html(pos);

At the bottom of the Nikebetterworld website, they show you how many pixels you’ve scrolled to reach the bottom of the page. I included this in the demo and the code above replicates that.

Whew, that’s it right? Almost!

Up to now, all of that code hasn’t actually done anything. We’ve simply set up lots of code to be activated when we need it. We just need a few events now to allow us to utilise all of those functions.

Immediately after the last function, I’ve called the function ‘RepositionNav()’. This is triggered immediately after the script loads to make sure the unordered list of links is vertically positioned in the window.

Next up is a window resize event:

$window.resize(function(){
    Move();
    RepositionNav();
});

When a user resizes the browser, we call the Move() and RepositionNav() functions. These both make sure that the demo works well regardless of the window size.

$window.bind('scroll', function(){
    Move();
});

And finally, the scroll event. When a user scrolls, call the Move() function to move the background images relative to the position of the scrollbar.

Conclusion

Having seen the Nikebetterworld website I was blown away but a little disappointed too. I didn’t get the chance to put my jQuery Parallax Demo into good use — it just existed as a demo. Having tried to replicate the Nikebetterworld website though, I have a lot of respect for whomever it was that developed it. Not only did they create a truly awesome effect, they made the website cross browser compatible too. They also used other cutting edge technologies such as HTML5 and font replacement to make a truly amazing experience.

Parallax effects are slowly being used across more and more sites. Having made this demo and learnt a lot along the way, I still have a lot of ideas for making the demo code better but also for taking the script in new directions and achieving even more amazing effects with it. Keep your eye on my blog for more techniques, or if you beat me to it, give me a shout because I’d love to see what you’ve made.

Written by Ian Lunn

Ian Lunn is a Freelance Web Designer based in sunny Devon, UK. He specialises in combining professional design, development and marketing techniques to create effective websites with a strong online presence.

This entry was posted in Code Tutorials and tagged , . Bookmark the permalink.
  • http://twitter.com/digitalbdesigns James Seymour-Lock

    Great! cant wait to try this, bookmarked for later reading, thanks!

  • Anonymous

    Thanks James, let me know how you get on with it.

  • Jeff

    I love you ! I mean I really love that’s stuff !!!

  • Anonymous

    Thanks Jeff :)

  • http://www.squareart.co.za Squareart

    This is really great, can’t wait to try it out – excited!! thanks dude!

  • Anonymous

    Thanks James, let me know how you get on with it.

  • Anonymous

    Would love to see if you make anything cool with this.

  • Anonymous

    Hey Ian,

    Thanks. This is great! When I saw the Nike site, I knew that’s how I wanted to redo the site for Tribes Win, my new media consultancy.

    Based on the Nike site, I’ve started putting together content “slides” in Keynote & defining different background objects.

    Would you be interested in a project developing my site? If so, let’s work up an estimate.

    You can email me at clay at tribes win dot com.

    Thanks, Ian. Keep leading.

  • Anonymous

    Thanks Clay, just sent you an email.

  • hannes

    hey, great tutorial! the localscroll-link is messed up though (just a bit).

  • Anonymous

    Thanks hannes.

    Can you explain what the problem is with the localscroll link please?

  • hannes
  • Anonymous

    Thank you :) Thought you meant in the demo. It’s fixed now.

  • Alan

    Hi Ian,

    thanks for doing up the tutorial! Just one questions. I tired viewing it on my iPad but it isn’t really working. Some images aren’t showing. do you plan to have another update to make it look good on ipad too? :)

    Alan

  • Anonymous

    Hi Alan,

    I am working on a plugin that improves the script and provides a lot more options for developers.

    I will take a look at making this plugin compatible with iPad. Due to the differences between desktop and touch devices though, the script may act/look differently between the two.

  • Carol

    Hi, Ian -

    I can’t thank you enough for this script and tutorial – it has saved me hours and hours of time in a project I’m currently working on.

    One small problem I have – I need to have a STATIONARY image that sits on top of the scrolling layer. It can’t be part of the background; otherwise, the scrolling layer will scroll above it. I tried positioning the image absolutely, but then the image scrolls along with the scrolling layer – grrrr – any suggestions about how to implement something like this?

    Thanks so much!

    Carol

  • Michelle

    awesome!!! wondering how do we put easing on the scrolling?

  • Anonymous

    Hi Carol, do you need to have it fixed so it doesn’t move with the scroll bar at all? Like my “Hire Ian” button in the demo? Or do you need it fixed but just in one section?

  • Carol

    Hi, Ian -

    Yes – the latter – I need it fixed but just in one section.

    Thanks, Carol

  • dm

    As far as I remember the inview script does not work with the latest jQuery version. You could use http://protonet.info/post/2516624585/jquery-inview-plugin instead. ;)

    Have not looked much into it but another nice approach is http://imakewebthings.github.com/jquery-waypoints/

    BTW: Awesome demo. Thanks!

  • http://www.facebook.com/profile.php?id=1028562610 Mehdi Ayache

    Excellent ! Thank you for sharing :) From @Morocco !

  • http://twitter.com/Ian_Lunn Ian Lunn

    Thanks for letting me know dm.

    Will be rewritting the script into an easy to use plugin soon with my own ‘inview’ script.

  • http://twitter.com/KingScooty Scotty Vernon

    Hey Ian,

    Any ETA on when that plugin will be ready? I’m currently using this tutorial to create a parallax effect for my own site, only problem is, it’s a little fiddly getting the background images to “start” in the same position on various screen resolutions.

    They seem to appear a lot further down the page the lower the resolution, which is a little frustrating.

    It would be real sweet if you could set a start position in pixels (like the background-position offset in CSS) and then apply the inertia from that starting position. Instead of going off the browser height.

  • http://www.ianlunn.co.uk/ Ian Lunn

    No ETA as yet, got to find some time to work on it. An early version of the plugin can be found here: http://ianlunn.co.uk/plugins/jquery-parallax-1.1/ but it doesn’t add any functionality as yet, just makes initiating the effects easier.

  • http://5050box.com 5050box

    Hi Ian,

    I am using your script as a teaser for my site. The actual site is still in beta since I recently decided to switch to Drupal. If you want to have a look what I made with your script the URL is http://5050box.com.

    Thanks for sharing and using your hands with some awesome jQuery… Apropos: I collect hands. http://5050box.com/hands. I would be honoured. ;)

    Daniel

    PS: I am dm with the inview hint.

  • http://5050box.com 5050box

    Hi Ian,

    I am using your script as a teaser for my site. The actual site is still in beta since I recently decided to switch to Drupal. If you want to have a look what I made with your script the URL is http://5050box.com.

    Thanks for sharing and using your hands with some awesome jQuery… Apropos: I collect hands. http://5050box.com/hands. I would be honoured. ;)

    Daniel

    PS: I am dm with the inview hint.

  • http://5050box.com 5050box

    Hi Ian,

    I am using your script as a teaser for my site. The actual site is still in beta since I recently decided to switch to Drupal. If you want to have a look what I made with your script the URL is http://5050box.com.

    Thanks for sharing and using your hands with some awesome jQuery… Apropos: I collect hands. http://5050box.com/hands. I would be honoured. ;)

    Daniel

    PS: I am dm with the inview hint.

  • http://5050box.com 5050box

    Hi Ian,

    I am using your script as a teaser for my site. The actual site is still in beta since I recently decided to switch to Drupal. If you want to have a look what I made with your script the URL is http://5050box.com.

    Thanks for sharing and using your hands with some awesome jQuery… Apropos: I collect hands. http://5050box.com/hands. I would be honoured. ;)

    Daniel

    PS: I am dm with the inview hint.

  • Oliv.

    Hi Ian,

    great tutorial, I’m really grateful for your effort on this matter

    I have a question ;) … Is it possibile to dynamically resize images to fit to browser size?

    I’d like to keep the ratio always the same.

    THANKS

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Oliv, yes you can resize the images but there are limitations. If they’re images, you may want to look into CSS background-size (which will scale images) or check out this jQuery plugin to resize background images: http://srobbin.com/jquery-plugins/jquery-backstretch/.

    If you’re using only simple graphics you could use SVG (scalable vector graphics).

    Let me know how you get on.

  • Oliv.

    Hi Ian,

    Thanks for your reply. Slowly getting thare…

    there is a bit of code that is not completely clear to me.

    if($firstBG.hasClass(“inview”)){ 2 $firstBG.css({‘backgroundPosition’: newPos(50, windowHeight, pos, 900, 0.3)}); 3 }

    The “900″ what is exactly referring to? I’m asking because I’m having trouble to align flush the BGs. All my BGs have the same height, but sometimes there is a small gap in-between.

    Many thanks

  • http://www.ianlunn.co.uk/ Ian Lunn

    This seems to be the value that is confusing people the most, I hope to make this easier to understand when I get a chance to update the code.

    The 900 is a value you need to specify to adjust the starting position of a background image. What happens is that the code takes the position value of an image but then multiplies that value to create the parallax effect. If your image is at 100px from the top of the document and you move that image at a tenth (0.1) faster than the scrollbar, it’s starting position will actually be 90px. To get it back to 100px you’d specify the adjuster value of 10.

    If you experiment by changing the value of 900 to say 1000, you will see the background image adjusts it’s position. This will allow you to prevent the white gaps between sections.

    Also remember that if your section has a height of 1000px and you’re moving the background image at a tenth quicker than the scrollbar, the background image will need to have a height of 1100px (a tenth taller than the section height).

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi dm, your sites looking really good. I like the effect you used on the hands page too.

  • http://www.PrairieRoseConsulting.com Carol Panzer

    Hi, Ian -

    Here is a link to a site I created using your script – rolled it out about a month ago or so. Thanks so much for providing your fabulous script… saved me an untold number of hours! Go to http://www.upyoursgallery.com/ and click on “Artists, get informed.”

    All the best, Carol Panzer

  • BH

    Are you planning on updating the script to work with newer versions of jQuery? There are some glitches right now when using 1.5.x or 1.6.x.

  • Berbertpk

     Hi, I’m a french art student, and your demo is great to show my work, but I have a little problem, if I try to put a link to the second page in the first one, it goes to the second page, but without scrolling smooth, where is my mistake?

    Thank’s a lot!

  • Ian Lunn

    Hi, if you check in the head section you will see this script:

    $(document).ready(function(){ $(‘#nav’).localScroll(); }) 

    This initiates the scrolling on any link within an element of ID ‘nav’. You should either place all your links in the ‘nav’ element or add another selector to this code, such as:

    $(document).ready(function(){ $(‘#nav, .another’).localScroll(); })

  • Berbertpk

    Thank’s a lot, you save me!!

  • http://www.nickdownie.com/icd Nick Downie

    Great article Ian, me and a friend have been experimenting with this effect since we saw the Nike site a while back for a university project. 

    We ended up having all sorts of problems with the javascript slowing the browser and the effect becoming jittery and laggy. Your tutorial and inview tip really helped us out creating our project.

    If you’re interested, we created a sort of interactive article, about colours in web design, showcasing some examples and combined with a colour palette generator. Its currently online at http://www.nickdownie.com/icd if you wanna check it out!

    Many thanks again!

  • http://twitter.com/KwakDesign KwakDesign

    I’m new to jQuery, I can’t seem to get the demo to work. It does not slide to each page but jump to them instead. Am I doing something wrong?

  • http://twitter.com/KwakDesign KwakDesign

    Hi Ian,

    I’m not sure if I’m having the same problem as the person below me but when I run the demo, the sliding effect does not work. I’m new to jQuery and was wondering if I’m doing something wrong.

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi KwakDesign, what browser/operating system are you using? Do you have JavaScript enabled?

  • http://twitter.com/KwakDesign KwakDesign

    I’m using Chrome, Safari and Firefox and on MAC OSX 10.6.7. I’m running the demo through Coda. Everything loads up fine but when I click the white circle buttons, it just jumps to the pages instead of sliding. I even tried copying everything over from your demo example and I still get the same problem. But your actual demo works fine! I think your a genius by the way! :)  

  • http://www.ianlunn.co.uk/ Ian Lunn

    Remember to include all of the JavaScript files. Also note the demo uses jQuery 1.4.4.

    Feel free to send over a link to your project if you’re still having issues.

  • http://twitter.com/KwakDesign KwakDesign

    Ian,

    I’m running your demo download. I even copied over your working demo and I’m still having issues. It just won’t slide over, it’ll just jump to the links. I tried using jQuery 1.4.4 and the current version. 

    Should I try running this on Dreamweaver? The weird thing is even when I run it on multiple browsers such as Firefox, Chrome and Safari I get the same problem. 

    Again I running this using Coda. 

    Thanks for the speedy reply!

  • Mbainbridge

    Great Tutorial!  I absolutely love it!

    THe only thing is that it does not look so good on my ipad of iphone.  I notices the the actual Nikebetterworld.com site looks ok on the mobile devices.  I mean, it doesn’t do the whole layered effect look, but scrolls down like one long page.

    Do you know any tips or tricks to make it look a bit better on the mobile devices?

    Cheers and thanks!

  • Karubin

    Hi Ian,

    I still have problem with getting the right adjuster value. I see that you have tried to explain that value a couple posts below. Somehow I still dont get a first smooth transition. When I move to my second slide, it makes a “jump”  and then scroll. The following clicks will give me a smooth transition though.

    Is there some formula I can apply to get the right adjuster value? 

    Thnx for the great tutorial :)

  • http://twitter.com/KwakDesign KwakDesign

    Ian,

    Sorry to keep bugging you, but I still can’t seem to get your tutorial demo working properly. Is there javascript file that’s outdated or missing? It’s strange because when I view the source on your demo page it’s pretty much the same as your tutorial download demo page. But every time I click on the nav buttons it just jumps to each page. I double checked localscroll and scrollto jquery files but everything seems to be in place. Unless I’m totally missing something. I really admire your work and especially this demo in general but I can’t get it to work properly. Please help. Thanks!

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi KwakDesign,

    I can confirm the downloadable files work from the get-go. I just downloaded to double check.

    When testing the demo yourself, do you get the parallax effect or does all JavaScript appear not to work?

    Also, are you extracting the demo files from the zip, as opposed to running them straight from it?

  • http://twitter.com/KwakDesign KwakDesign

    Hi Ian,

    I don’t get any parallax effect and yes it does seem like the Javascript is not working properly.

    I’m not sure if I get what your saying about running the demo straight from it. I downloaded the zip and extracted the files from it and ran the demo.

  • http://twitter.com/KwakDesign KwakDesign

    Ian,

    So I figured out the culprit is Coda! When i run the index.html from Dreamweaver it works perfectly fine! It’s very strange though why it wouldn’t work through Coda. I’ve never had any issues with Coda before. 

  • ashleyemma

    Hi,

    This tutorial is great, I have downloaded the files and it worked straightaway. I do have one question though, I was just wondering if it is possible to make one of the images move horizontally across the screen instead of vertically? Can this be done? =)

  • Marc

    Hi Ian,

    Brilliant Demo. I went thru the tutorial and worked perfectly 2 weeks ago, now i’m starting my own. All I have done is duplicated the folder the tutorial was in and its stopped working. The links don’t smooth scroll. Its bizarre.

    Any clues?

    Marc

  • Marc

    Oh Mac 10.6.7 Safari 5.0.5. Opened My tutorial which works from Finder. Duplicated same folder and opened again in finder, and smooth scroll stops working when clicking same links.

  • Marc

    Just by chance found out why it wont scrollto. downloaded demo files “recreate-nikebetterworld-parallax”. Renamed folder “123″ and works perfect. Renamed again to “1 23″ and behold – no scrollto. Must be Mac thing

  • http://www.facebook.com/people/Adriana-Mandjarova/100000210492993 Adriana Mandjarova

    Hi Ian,

    Thank you so much for the tutorial it is just AWESOME!

  • LB

    Hi Ian,

    Just wondering what is the best way to add additional sections with multiple backgrounds, such as the sneakers section?

    Should I duplicate the css and html for that section, and rename it, as well as duplicate the selector and functions and rename accordingly?

    Cheers

  • Anonymous

    Wow!  This is better than both the tutorial shock ( http://www.tutorialshock.com/tutorials/single-page-portfolio-vertical-parallax-jquery-css/ ) and smashing mag http://coding.smashingmagazine.com/2011/07/12/behind-the-scenes-of-nike-better-world/ articles, in my opinion.  The mechanics on the tutorialshock demo are only maybe 75% done and the SM article has poorly written/redundant code (see my comment there) that makes me less than confident in the code as a whole.

    Thanks!

  • Hemant Shah25

    Hi Ian,

    is there any script for iPad device?

  • Avian Prasetyo

    Hello Ian,

    i’ve downloaded the demo, unzipped it and tested, but it doesn’t work when i tested in my safari (Version 5.1). the screen just jumps to each section/page every time i clicked the nav-buttons

    i’m not good with .js kinda stuff and i’ve tried to follow the tutorial line by line.. but the result is still the same (with safari 5.1) but works fine with chrome, ff and ie.. did i missed something? please help..

    great tutorial by the way..

    thank you.

  • Avian Prasetyo

    i have the same problem. But not with coda. The problem appear when i opened the download file and browse it from safari 5.1 (it works great with chrome, ff and ie), the animation won’t work, it just jumps to each page. But when i open the demo page, the parallax works just fine with safari.

    i’m a newbie in javascript. please help..

    great tutorial by the way. thank you.

  • http://webberry.wordpress.com Ajinkya

    This is really awesome n unique tut. I always used to think wht if someone shares code of nike’s website. :)

  • edis

    Hello Ian, nice recreation, great work. Just a question though if you have the time: on the actual nike site they have this green line that  helps guide the users attention (in my opinion) from the title of one article to another. Now how did they do it?  Keep up :)

  • Drumartinshead

    I was wondering the same thing about support for iOS devices. It might be nice to at least have it degrade gracefully to a normal page scroll on these devices to prevent the serious breakage that happens now. Just a thought. Thanks for the script and all your hard work!

  • Loughlin

    Probably one of the best tutorials and best documented pieces of jquery I’ve come across along.  this is super work Ian, massive amounts of respect to you sir.

  • http://www.facebook.com/people/Alon-Lala/100001880840192 Alon Lala

    Theres an amazing iPad menu app  for restaurants,  look for it in the appstore: emenu 4 rest. http://www.emenu-international.com/iPadMenu

    the same company(eMenu) which makes eMenu 4 rest has a desktop application for restaurants that is installed at over 900 places worldwide. you can see it over here: http://www.emenu-international.com

  • jaslyyfrankyh

     Nice article, thanks for sharing this information Cheap WOW Items. Good to know that this blog is being covered also in this web site.

  • jaslyyfrankyh

    Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing Tera Power Leveling. Keep blogging.

  • WhatchuTalkinBoutWillis

    Ian, just came across your blog. Great work man! Thanks so much for putting so much effort into this. I look forward to your optimized code. If I could recommend one bit of functionality that rounds out your offering (IMO) it would be to add navigation links (with easing) to particular stopping points as witnessed here (on the right) - http://yebocreative.com. 

    Thanks again, and keep up the good work! This is valuable stuff. 

  • WhatchuTalkinBoutWillis

    Uh, nevermind. Didn’t see the nav links were already there. 

  • WhatchuTalkinBoutWillis

    Uh, nevermind. Didn’t see the nav links were already there. 

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Edis,

    I agree, the green line leads the reader through the experience well.

    It is achieved using a Canvas element placed over the top of the page. You can reference their script here: http://www.nikebetterworld.com/lib/js/htmlcanvas.js

  • http://www.ianlunn.co.uk/ Ian Lunn

    That’s correct. Just remember to give the new section a unique ID.

  • Avenkumar

    woow, thanks alot.. it was very helpfull!

  • Chris M

    I would love to move an element from one side of the screen to the other, is that possible?

  • Derek Petersen
  • Aaronbrako

    Ian, if I were to make each background image 1000px high, what would need to be my adjuster values for each of the four ?

  • http://twitter.com/espaco99 Fernando Sousa

    podes mostrar-me o código modificado? já tentei modificar de da forma como perguntas ao Ian, mas comigo dá erro :-(

  • http://twitter.com/espaco99 Fernando Sousa

    I tried, tried and tried … but does not work :-( can show a simple example? So I see what I can to be doing wrong;-)Thank you.

  • http://twitter.com/espaco99 Fernando Sousa

    Hello Ian, thanks for the tutorial is fabulous. I am using your script to make a website for a jazz festival, but I’m having trouble understanding how the backgrounds and images .bg #second run in, especially when I want to repeat the block Can you give me a hand? Or provide a small example? Here’s the url of the beta site http://www.cm-seixal.pt/seixaljazz/2011/

    Another issue is the image .bg on top jump of the site when I start to scroll, what am I doing wrong?

    Thanks from Portugal.

  • edis

    Sorry, haven’t seen your comment earlier . . . Thnx for the reply, much appreciated, will check it out today.

  • Kris

    Hi Ian! Great work on this! Super! Only thing is that, the parallax doesnt work on safari. I just jumps on the page. :( but works perfectly on all Ff, Chrome, IE.  I’m a web designer and not a developer. How do I resolve this? Thanks! :)

  • Flashvenom

    Awesome tutorial very helpfull, I want to do a horizontal scrolling version of the same effect what would you suggest, just changing the window height values to window width etc?

  • Andrés Redondo

    Hi Ian! I´m trying to do a exercise with your scripts and i can´t put the intro div to the top. I quit the jquery.inview script and the div puts automatically into top of the page. Can you say me why this script left a margin between the top of the page and the first div and how can i quit this margin? Sorry for my bad english and thank you so so much, it´s a great tutorial. Andrés.

  • Anonymous

    great, great stuff you put here. thank you so much for sharing it with us all.

  • http://www.ianlunn.co.uk/ Ian Lunn

    Scrolling doesn’t work in Safari when viewing the demo locally. Upload it to a server.

  • Andrés Redondo

    Great Ian! Thanks for your post!

  • Rachel

    This is an amazing tutorial. The only problem is I can’t get it to work on an ipad?

  • Markosansa

    Hi Ian! Very interesting post but during this week I tried to add a useful variant but no work. I you see the nikebetterworld menu you can see that when you scroll every bullet is activated. 

    Suppose I have to call a class in the nbw-parallax js but i don’t understand what I have to do.. Can you explain me wich part of code I have to modify and implement?

    Thank you so much advance. 

  • Martin

    Hi Ian – Excellent work on this, love it – but the new version doesn’t seem to be working in any of the IE browsers?  Scrolls without the parallax effect working…

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Martin, please could you try again and let me know if it’s now working for you in IE.

  • Martin

    Hi Ian – still no joy, I’m afraid.  It’s only stopped working since your latest 1.6.4 release on GitHub, after I updated my files.  Works fine after testing FF, Chrome, Safari et al.

  • http://www.johnrockefeller.net/ John Rockefeller

    What about in cases where the height of the div it’s in is not defined?

    For example, let’s say I have a site where I’d like this to appear on every page, even sub-pages within the site. Obviously, each of these pages will have a different height depending on the content.

    I’ve snapped the scroller to the container div of each page and am having huge issues the second I go to scroll. The javascript moves the background image way out of whack vertically. One assumes it’s having difficulty figuring out the height of the div.

    Can anyone help please?? :(

  • Abhishekdas 13

    Hi Ian! great work mate! Trying to implement your plugin into one of my project. I have not been able to add a link in the content areas like . Any suggestions to solve it?

  • Dshegna

    Hi Ian! Thanks for the great tutorial and script. But i have som issus i cant seem to figure out.

    Whenever a im trying a low resolution the elements floats apart and it look really clumsy, and in chrome the site becomes really heavy when scrolling. Any ideas? http://www.dshegna.com

    And again, thank you for a great script. Really helps me out with my school project ;)

  • Dshegna

    My question was is there any way to scale the whole site to the resolution of the user? :)

  • http://john-beadle.com/ John

    Great tutorial thanks for posting this…

    Is it possible to have a fixed width rather than a min width. I have a site with 10 stories and a fixed width of 916 px.

    Thanks in advance

  • Praudjean-remy

    Thanks for your work! I’m starting to learn Jquery and it really helps me, even if some codes keep being weird to me. You can see the result here:

    http://www.jeanremypraud.com

    Thanks again!

  • Asymetricalflake

    Any chance you happen to have a solution or work around for different browser window heights? I can chance all the values in the Javascript so that it looks awesome on a 800px high window, but then when I open it on a 1200px window bg images start getting cut off. If I optimize it for large monitors, the same thing happens.

    I suppose I could code something that say if the browser height is greater then 800px instead of 50% in the window value use 75%.

    Or I would just call different js files based on browser height.

    Any thoughts?

    Thanks.

  • hikups

    Did somebody allready tried this code? I tried it on my ipad and it seems to do the job, but it’s kind off complicated to dive into the code and create something from it. I see a lot of new parallax website popping up, but non of them seems to work on an ipad. Would be cool to see this in combination with this tutorial, with multiple backgrounds.  thanks !

  • Frederic

    Hi Ian, 

    this is a great tutorial and has helped me create a great website which I am getting really excited to launch sometime in the next couple weeks. I was wondering though if there was any way of layering moving elements on top of text, or if the only way of doing that was by making an image out of the text and using it as a background image.

    Here is the adresse: http://newhybrid.concordia.ca/f_bouin/final/ (the site needs a preloader it might take a second to load up)

    The typography at the top is written in html and styled in css. I would like some of those moving clouds which are underneath to be on top… Can this be done?

    Thanks again

  • Nathan

    Hi Ian! Really great work. Thanks a lot for sharing!

    I’m trying to get this work with the newest WordPress version, which uses Jquery 1.6.1. I could not get it work without loading Jquery 1.4.4 too. Any chance to get this work with the library WordPress comes with (and further updates)? I don’t want to load Jquery twice.

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Nathan,

    The latest version of the plugin works with jQuery 1.6.4: http://www.ianlunn.co.uk/plugins/jquery-parallax/

  • Ralph D

    Great work! I tried both on ipad and IPhone and I get errors back on both. Please any updates on this working on IP andI ph?

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Ralph,

    Please see this post regarding iOS support:

    http://www.ianlunn.co.uk/blog/code-tutorials/javascript-parallax-effects-a-deeper-look/

    It is possible to support iOS but with a lot of hacking. I’d strongly recommend you remove the parallax effect when a user is viewing your site on these types of devices as described in the link above.

  • Bentonrochester

    Hey Ian, Thanks for the tutorial! Pretty awesome stuff. 

    Big Question: I was hacking your script and ran in to a problem.  Why does it say “[an error occurred while processing this directive]” after each page? Even using your exact code? 

    http://www.bentonrochester.com/parrallax http://www.bentonrochester.com/Site2.0

    Thanks B

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Benton,

    That occurs on some servers due to the HTML comments. Remove comments such as these <.!–.story—> to resolve that issue.

  • Bentonrochester

    IAN!!!! 

    It worked! I should have asked you 5 days ago. You have really helped, thanks!

    b

  • Mannu Elewaut

    Hi Ian,

    I can’t get rid of those errors even after removing the html comments…

  • Ly_jordan

    Hey Ian, how to I make a horizontal scroll instead?

  • Manuel

    Hey Ian, Like everyone I must thank you for all your hard work! Really awesome stuff. I incorporated your plugin into my site but I have a small problem. When the page loads there is a good 30 or 40 pixel gap between section 1 and section 2 at their start positions. Once scrolling begins, it goes away. Any thoughts on why this is occuring? The page is http://www.21stcenturywebdesign.com/webdesign.html. Thanks again for all that you ave done so far!

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Manuel, you must consider how your website appears on larger resolutions as well as your own. It is wise to create background images that are big enough to appear on the biggest resolutions to prevent gaps from appearing.

  • Allstarfever

    hi, which part is for the pixel count at the bottom of the page, sorry im a newbie! 

  • http://www.ianlunn.co.uk/ Ian Lunn

    Place an element in your HTML with an ID of “pixels” and use this jQuery:

    $(‘#pixels’).html($(window).scrollTop());

  • http://www.gordonmcgowan.co.uk/ Helen

    Thanks Ian for an inspirational and informative tutorial

  • Neil

    I am trying to create more links other than the main nav to slide to other content, like a ‘down’ or ‘next’ button. It just seems to jump to the content instead of sliding there. How do I add more buttons that link in the same way?

  • Dexter

    Hello.

    I have run into a bit of a problem. Please help me.

    Is there a limit to the number of slides/ articles that I can add?

    I wanted to add more than 4 articles. So I made the necessary changes. But when I added #fifth in the “apply the class inview to a section that is in the viewport” part, the whole thing stopped working. [line 31 in nbw-parallax.js file]

    When I removed #fourth form the line (so that there were only 4 sections), the script started working again.

    What should I do to enable 5 or more sections?

    Please reply.

  • Paul Holcomb

    THANK YOU!!  for posting this – I’ve been wanting to learn how to do this.

  • http://twitter.com/Jarallax Jarallax

    i’m currently working on a Javascript library Jarallax. With Jarallax you can ajust css based on user interaction. Jarallax is keyframe based, you can write your own custom controllers. By default Jarallax usses a scroll controller (simmilar to parallax scrolling websites). but its easy control with a webcam, mouse position, databases, etc.

    http://jarallax.com

  • Shannan Rohde

    A great tutorial.  I was looking for something like this for a while.  I will post my final results and creative idea when finished.  You are a great Teacher Ian. Warm regards, Shannan Rohde

  • Johe

    Really great tutorial, just a quick question about the navigation…

    I’ve managed to change a navigation item to another colour when a user is on a particular section; by changing its class within the Move function e.g.

    function Move(){  …

    if($firstBG.hasClass(“inview”)){    $firstBG.css({‘backgroundPosition’: newPos(50, windowHeight, pos, 1045, 0.3)});      document.getElementById(“btn-one”).setAttribute(“class”, “menuon”); … … }

    However, this seems to instigate the class change as soon as a section is slightly in view – for example, if you are on the first section, but can see the second section creeping in below (due to a long browser window) it thinks the second section is in view and changes the navigation colour.

    Where instead should I add this script so that it only instigates once the full section is in view (i.e. after clicking on that sections navigation element or scrolling far enough downwards)?

    Thanks.

  • http://www.aaronhawkins.co.uk/ Aaronhawkins

    Hi Ian, Just wanted to echo what many before me have and say what a great tutorial you have put together here. Fantastic stuff! I am however having an issue and having spent an entire evening trying to work it out thought I would turn to its creator… I followed your instructions step by step and have it all working perfectly. Except the second trainer is not moving, have you any ideas why this might be? The trainer shows up just doesnt move. All the other elements move as expected (although I am not doing the 4th as I want mine to be compatible browser wide). I wondered could it be to do with me working locally on my machine and wamp server? Otherwise I have no idea… Would really appreciate any tips or pointers you could give. Thanks Aaron

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Aaron, do you have a link to the project please?

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Johe,

    I’d recommend using the plugin I wrote (a slightly updated version of this tutorial demo):

    https://github.com/IanLunn/jQuery-Parallax

    I rewrote the inView function which will only trigger your custom code when a section is completely in view.

  • http://www.ianlunn.co.uk/ Ian Lunn

    Looks good :)

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Dexter,

    There are no limitations to the number of slides you can have. Please provide a link to your project so I can take a look at what’s going wrong.

  • http://www.ianlunn.co.uk/ Ian Lunn

    Hi Neil,

    The scrolling is controlled by localScroll which is not my own script. Please see its documentation: http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html

  • Aaronhawkins

    Hi Ian, at the moment I have just been working on it locally.. this evening I will upload to my server and send across the link. Thanks for the reply.

    I am yet to get the time to look into it, but can your script be converted into a side scrolling site? I have seen a few examples below and might have a play doing things that way also.

    Just getting into Parallax effects, your stuff has been a great help!

  • http://twitter.com/okhy Gembong Yudo P

    This is absolutely amazing & (literally) makes me drooling.

    ps: by literally I meant literally, I drooled a bit. Haha.

  • Cheemik

    i want that asap! how long is it gonna take mate? ;)

  • Jackohoogeveen

    I’m planning to go opensource within 7 days :) Currently i’m building some tutorials and fixing some minor bugs

  • aeg

    Hi,

    I am using your plugin and it is great – fantastic effort. I just have a quick question, when I change the images to my own it seems to stutter the parallax effect for some reason?! I am using the same image width, height and extension…any ideas as to what could be causing this? Thanks