Parallax Behind The Scene

Most popular and discussed web design effect of the last few years is the parallax scrolling effect. It involves the background moving at a different speed than the foreground when you scroll down the page.

In this tutorial I will discuss How simply you can add this awesome effect to make your website beautiful.


Simply we need to make difference between background position and foreground position of the Dom at the time of scroll.



We’ll add some code that can make body background scroll faster than document scroll.

Behind the scene

First we have to attached an image as a background using css background property.

 body {
        background: url('');
	/* a random image, thanks google image search!*/

Now on scroll we’ll change background position using some mathematical calculation between document scroll position and body scroll position.

before that we’ll also fixed our body background image.

In window onload we’ll initialize all above functinality.

So here is our javascript the code.

		window.onload = function() {"fixed";
			window.onscroll = function() { = "0px " + (0 - (Math.max(document.documentElement.scrollTop, document.body.scrollTop) / 8)) + "px";

Now, we are done. Please check the demo and revert if you have any query. In next tutorial we’ll discuss more on advance parallax effects.