
We already made the function to generate the image filepath based on the number we pass into it so what we need to do now is track the user’s scroll position and determine the corresponding image frame for that scroll position.
#PARALLAX CSS IOS UPDATE#
We want to draw the images on the and update the drawing with the next image in the sequence (but we’ll get to that in just a bit).

And we don’t merely want to load one image file and then swap it out by loading another image file. What we want is to update it based on the user’s scroll position. Here’s the first image in the sequence drawn on the element:Īs you can see, the first image is on the page. That gives us a way to handle image paths. So, for example, passing 1 into this function will return 0001. Since the image number is an integer, we’ll need to turn it in to a string and use padStart(4, '0') to prepend zeros in front of our index until we reach four digits to match our file names. The last thing we’ll do is position the, center it, and limit the max-width and height so it does not exceed the dimensions of the viewport. We’ll also match the background color of the document with the background color of our images. In CSS, we’ll give our document a height of 100vh and make our 5⨉ taller than that to give ourselves the necessary scroll length to make this work. The HTML and CSS for this effect is very easy as the magic happens inside the element which we control with JavaScript by giving it an ID.

You know, like a flip book! No complex WebGL scenes or advanced JavaScript libraries are needed.īy synchronizing each frame to the user’s scroll position, we can play the animation as the user scrolls down (or back up) the page. The idea is to create an animation just like a sequence of images in rapid succession.
#PARALLAX CSS IOS PRO#
Specifically, let’s replicate the AirPods Pro product page and the shifting light effect in the hero image. Let’s take an in-depth look at one of these effects to see how it’s made so you can recreate some of these magical effects in our own projects. Even using the browser’s DevTools won’t always reveal the answer, as it often can’t see past a element. What then, you ask? Well, it can be a little hard to figure out. Just check out this video of the mobile web experience for the iPad Pro: Source: TwitterĪ lot of the effects that you see there aren’t created in just HTML and CSS. For example, as you scroll down the page products may slide into view, MacBooks fold open and iPhones spin, all while showing off the hardware, demonstrating the software and telling interactive stories of how the products are used.

Apple is well-known for the sleek animations on their product pages.
