Parallax Effect

A CodePen Project

I looked long and hard for a good parallax scrolling library on the internet, and always came up short. The libraries I found all had one issue in common: they would all break at a certain image size. It seemed like no one had their math right. So I set out to accomplish it myself, using a reusable custom element.

This supports multiple parallax layers, whose distance from the "camera" is determined by a number from 1 to 6. As you can see in the demo, there are 3 layers animating independently. I had a lot of fun with this!

I've more or less reused this code on this website and others, though I've adapted it to different libraries with different needs. I can't guarantee I'd write it exactly the same way today, but the base concept is there and it works! Huzzah!

Tools Used:

  • JavaScript (ES6+)
  • CSS3
  • Custom Elements