Adding an interactive parallax background to a webpage

Basith Kunimal
2 min readMay 7, 2021

--

This tutorial shows you how to add interactive parallax backgrounds to your website. You can move your mouse around and see the layers move around like below.

Check out the demo here

Implementation

We’ll not be using any libraries to build this feature, just vanilla javascript. In this example I’ll be showing you how to write this as a react component but the overall workings are the same and you can expect this to work in plain javascript.

And later on you can use this component like

Make sure you order the images in that order so they stack on top and don’t cover each other. Also you’ll have to use PNG or some other formats which has transparent parts. If you want the asset files, you can find them in this github repo.

NPM package

If you’d like, I’ve already made an npm package of this component. There is also a working example in the github repo.

--

--

Basith Kunimal

Web Developer. Biker. Armchair Historian. German language student.