Skip to content

Use the CSS transforms translateZ() and scale() to create a parallax effect on scroll using only CSS.

Updated: at 04:25 PM

You know those cool parallax mastheads and slick parallax backgrounds? Yeah, you can do those using only CSS.

Give an element a negative translateZ value and then calculate the scale needed using this equation:

1 + (translateZ * -1) / perspective = scale

Paul Irish left a comment with more demo links:

http://codepen.io/scottkellum/details/bHEcA is where I first found this technique. I believe Scott adapted the technique by Keith. The demo in that pen has a nice 3d view of parallax on two-axises. Plus, Scott’s created a mixin that automates most of the work for you. Really handy.

http://codepen.io/keithclark/details/JycFw/ by Keith has a more flashy demo of this technique.

http://frozenrockets.nl/labs/parallax/ has a good example of your standard masthead parallax. It could use some layer promotion to avoid paint storms on non-retina but it looks great.

Read more from the source: blog.keithclark.co.uk