<!DOCTYPE html>
<html>

<head>
    <title>Parallax Scrolling Example</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="css/main.css" />

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css" />
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/parallax.js"></script>
</head>

<body>
    <nav id="main-nav">
        <ul>
            <li><a class="earth" href="#earth">Back Home</a></li>
            <li><a class="moon" href="#moon">Moon</a></li>
            <li><a class="rocket" href="#rocket">Space Flight</a></li>
            <li><a class="saturn" href="#saturn">See the Planets</a></li>
        </ul>
    </nav>
    <div id="earth"><img id="img-earth" src="img/earth.png" alt="earth" /></div>
    <div id="stars"></div>
    <div id="images">
        <img id="img-moon" src="https://www.pa.msu.edu/people/frenchj/moon/moon14day-1985c.jpg" alt="moon" />
        <img id="img-rocket" src="https://upload.wikimedia.org/wikipedia/commons/1/14/Proton_Zvezda_crop.jpg" alt="rocket" />
        <img id="img-saturn" src="https://upload.wikimedia.org/wikipedia/commons/7/7e/Saturn_with_auroras.jpg" alt="saturn" />
    </div>
    <!-- end of "images" -->
    <div id="content">
        <article id="home">
            <h2>Welcome to Outer Space</h2>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
            <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.</p>
            <p>Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.</p>
        </article>
        <article id="moon">
            <h2>Fly Me to the Moon</h2>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        </article>
        <article id="rocket">
            <h2>Rocket Man</h2>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        </article>
        <article id="saturn">
            <h2>See the Planets</h2>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        </article>
    </div>
    <!-- end "content" -->
</body>

</html>
/*********************** STARS *********************************/

#stars {
    background: #425169 url('http://www.thecollegesolution.com/wp-content/uploads/2015/05/stars_wallpaper_hd_widescreen.jpg') top center;
   
    width: 100%;
    height: 8000px;
    position: fixed;
    top: 0;
    z-index: 100;
}


/********************** IMAGES ********************************/

#images {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 200;
}

#images img {
    padding-top: 50px;
}

#img-moon {
	width: 400px;
	height: 400px;
    position: absolute;
    top: 1500px;
    left: 50%;
}

#img-rocket {
	width: 270px;
	height: 550px;
    position: absolute;
    top: 3000px;
    left: 50%;
}

#img-saturn {
	width: 600px;
	height: 400px;
    position: absolute;
    top: 4500px;
    left: 50%;
}


/********************** CONTENT ********************************/

#content {
    position: relative;
    margin: 0 auto;
    width: 960px;
    color: #fff;
    z-index: 300;
}

#content article {
    padding-top: 50px;
    width: 350px;
}

#content article h2 {
    color: #b1c2cd;
    font-size: 34px;
    margin-bottom: 0;
}

#content article#home {
    width: 960px;
}

#moon {
    position: absolute;
    top: 2775px;
}

#rocket {
    position: absolute;
    top: 5775px;
}

#saturn {
    position: absolute;
    top: 8775px;
    padding-bottom: 800px;
}


/*********************** EARTH *********************************/

#earth {
    width: 100%;
    position: relative;
    text-align: center;
    z-index: 900;
}


/*********************** NAVI BAR *********************************/

#main-nav {
    width: 100%;
    height: 35px;
    position: fixed;
    margin: 0;
    padding: 0;
    background-color: #303d50;
    z-index: 1000;
}

#main-nav ul {
    width: 960px;
    margin: 0 auto;
    height: 25px;
    padding-top: 10px;
}

#main-nav ul li {
    float: left;
    width: 200px;
    height: 30px;
    padding-left: 0;
    list-style-type: none;
    text-align: center;
}

#main-nav ul li a {
    color: #f1ecb9;
    font-weight: bold;
    text-decoration: none;
}
$(document).ready(function() {
	
	$(window).bind('scroll', function(e) {
		parallax();
	});
	
	$('a.earth').click(function() {
		$('html, body').animate({ scrollTop:0 }, 1000,
			function() {
				parallax();
			});
		return false;
	});
	
	$('a.moon').click(function() {
		$('html, body').animate({ scrollTop:$('#moon').offset().top }, 1000,
			function() {
				parallax();
			});
		return false;
	});
	
	$('a.rocket').click(function() {
		$('html, body').animate({ scrollTop:$('#rocket').offset().top }, 1000,
			function() {
				parallax();
			});
		return false;
	});
	
	$('a.saturn').click(function() {
		$('html, body').animate({ scrollTop:$('#saturn').offset().top }, 1000,
			function() {
				parallax();
			});
		return false;
	});
	
});

function parallax() {
	var scrollPosition = $(window).scrollTop();
	$('#stars').css('top', (0 - (scrollPosition * .2)) + 'px');
	$('#images').css('top', (0 - (scrollPosition * .5)) + 'px');
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.