
This calls for a little bit of detail into how scale works. The whitespace on top of our pretend-foreground pastel-red-div will keep changing. Open the Pen above in a new tab and resize your window vertically. The far away element is now 500px in height, but there still seems to be some whitespace remaining atop the element. So that would mean that the translation scales our image down by 1/2, and so scaling up our original element by 2 would make it appear to be 500px in height. Since we set z to -1px and p to 1px, we get: The next things we want to do is make it appear to be 500px in height so that it fills up the 500px gap. It also has some whitespace around it because of its projection ( d in Fig 1). The background appears smaller because it has been pushed away. Now we have a gap of 500px from the top of the viewport in the foreground plane. Otherwise, the perspective instructions would be ignored.

We want the entire viewport to be our view into the 3D world, so we’ll create a #container element that covers the whole viewport.Let’s define the element through which we’ll be viewing our 3D world. The larger the value, the less intense it is. The lower the value of p, the more intense the 3D effect. The perspective property essentially defines the length p from the figure above (Fig 1). Tell the browser how far you want the projected surface to seem to be from your eyes.īoth of these things are done by defining the perspective property on an element.Choose an element to be your 3D projection surface.The first step here is defining the perspective: This is essentially the same thing as drawing in 3D. Web elements can be positioned anywhere, and the browser rendering engine will project those elements onto our screen and let us view them.

The point C is the computer screen center, and the top-left corner of the screen (from the user’s point of view) is the origin. A brief aside into CSS 3D geometryĬSS’s 3D transforms allow us to look at the elements of a website like this: Voila, parallax! Exactly how it works in the real world. Scrolling vertically then makes things further away move slower and the things in front move faster. But if we look at a website as a 3D world projected on our computer screen, we can move some stuff really far behind our screen, and let some other stuff remain in front. This is unusual for a website, where normally all elements are placed on a flat plane and everything moves at the same speed when you scroll. It is a layered effect of different elements moving at different speeds.

Essentially elements that are “closer” to you move more quickly and elements “farther away” move slower as you scroll. His key idea behind parallax is beautifully simple. We built our CSS parallax based on (perhaps the first) CSS parallax concept by Keith Clark. Finally, we include a checklist of things to consider for performance in general. Next, we show some interactive features that are possible through CSS alone. First, we’ll focus on the scrolling parallax effect. In this article, we’ll tell you about the challenges we faced in both the design and speed optimization of the site, and how we overcame them. They have kept the site up that this article refers to at ”, and I’ll change the links in this article to that.Īnother Update: Looks like the “old” site is dead now too, we’ll just remove all links to it.Īt 34 Cross, we wanted to develop our new website to be responsive, mobile-friendly, and easily load on even 2G networks using only HTML and CSS. Update: they have updated the site since this article was published. I was like, hey, you should write about it! This is that. They emailed me to show me their new website and how performant it was despite having cool features, being visually rich, and responsive. The following is a guest post by Rajoshi Ghosh and Tanmai Gopal of 34 Cross.
