Parallax Scroll Effect Tutorial JavaScript Animation Programming

Adam Khoury · 162K views · 2014 · 9:23

Open on YouTube

Web developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it as the source tutorial for a simple window.pageYOffset parallax function, both as an answer and as the reference askers are following when their copy of the code does not work.

Recommended by 1 people across 1 different months, 2015 to 2016.

What it is

A short tutorial by Adam Khoury on building a parallax scrolling effect in plain JavaScript. It explains the idea of layers moving at different speeds, compares it to Disney's multiplane camera, and builds the effect with essentially one line of code tied to the scroll event.

What people said

Strong rec Adan · 2015-07 · Stack Overflow · on “html5 how to change position of image while user is scrolling down”

using this parallax function, an image that's in front of the background will scroll along the users scroll, heres a great tutorial video on parallax step-by-step: [this video] and lastly here's the code: function parallax() { var topdiv = document.getElementById('topdiv'); topdiv.style.top = window.pageYOffset + 'px'; } window.addEventListener("scroll", parallax, false); topdiv = target image you want to move while user is scrolling. it's id belongs to a div element. in order for this to work you must have a background image in the body that is *fixed. then use div to call another image *the moving image in a div element (or possibly other ways), then add in this function and that's it, as for c

Cites Tyrii · 2015-01 · Stack Overflow · on “Trying to add Parallax scrolling to a website that is already designed. It isn't working for some reason. Can someone assist?”

I'm trying to add Parallax Scrolling to a website that is already designed. It isn't working for some reason. Can someone assist? The tutorial that I was using is this one. [this video] This is the script that I wrote: <script> function parallax(){ var intro_section = document.getElementById ('intro_section'); intro_section.style.top = -(window.pageYOffest / 10)+'px'; } window.addEventListener("scroll", parallax, false); </script> This is the HTML section that I am trying to add the effect to. <div id="intro_section" class="clearfix"> <div id="Intro_section_container" class="clearfix"> <p id="We_Know_Why_You’re_Here" class="animated fadeIn" data-wow-delay=".2s"> We Know Why Your Here </p> <p id="

Cites Alexandr Belov · 2015-03 · Stack Overflow · on “Parallax scrolling”

I'm trying to make a parallax effect according to this tutorial [this video] But my function doesn't apply to my objects. Here's the function: function parallax() { var sphereOne = document.getElementById("sphereOne"); sphereOne.style.top = window.pageYOffset +'px'; }; window.addEventListener("scroll", parallax, false); I know I can use hundreds of JQ libraries instead to achieve the effect, but want to understand what's wrong. My objects just stuck at the same place when scrolling. Here's the JSFiddle example: jsfiddle.net/hkbusbkm

Cites KCKim · 2016-05 · Stack Overflow · on “Parallax Scrolling--Image not behind”

Well it's a YouTube video [this video] I just replaced the images and made minor image positioning adjustments because I don't have the images he uses.