Ajax Loader
HTML
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
1
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
2
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
3
<h1>Space Parallax</h1>
4
<div id="foreground"></div>
5
<div id="background"></div>
 
CSS
h1 {
1
h1 {
2
color: white;
3
font-family: "Lato", Arial;
4
text-align: center;
5
z-index: 2;
6
position: relative;
7
}
8
div {
9
position: absolute;
10
top: 0;
11
left: 0;
12
right: 0;
13
bottom: 0;
14
}
15
#background {
16
z-index:1;
17
background: url(http://css-tricks.com/examples/StarryNightCSS3/images/background.png);
18
}
19
#midground {
20
z-index: 2;
21
background: url(http://css-tricks.com/examples/StarryNightCSS3/images/midground.png);
22
}
23
#foreground {
24
z-index: 3;
25
background: url(http://css-tricks.com/examples/StarryNightCSS3/images/foreground.png);
26
}
 
JavaScript
var strength1 = 50;
1
var strength1 = 50;
2
var strength2 = 100;
3
var strength3 = 200;
4
$("html").mousemove(function(e){
5
    var pageX = e.pageX - ($(window).width() / 2);
6
    var pageY = e.pageY - ($(window).height() / 2);
7
    var newvalueX = 1* pageX * -1;
8
    var newvalueY = 1* pageY * -1;
9
    $('#background').css("background-position", (strength1 / $(window).width() * pageX * -1)+"px "+(strength1  / $(window).height() * pageY * -1)+"px");
10
    $('#middleground').css("background-position", (strength2 / $(window).width() * pageX * -1)+"px "+(strength2  / $(window).height() * pageY * -1)+"px");
11
    $('#foreground').css("background-position", (strength3 / $(window).width() * pageX * -1)+"px "+(strength3  / $(window).height() * pageY * -1)+"px");
12
});
 

Space Parallax

CSSDeck G+