Fullscreen slides

In this example below you will see how to do a Fullscreen slides with some HTML / CSS and Javascript

//Forked from Chrysto's Pen Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin. Optimized with the help of Blake Owen

Thumbnail
This awesome code was written by mikeK, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright mikeK ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Fullscreen slides</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <body>

	<nav>
		<ul>
			<li><a href="#slide-1" id="Slide01" class="active"><span></span></a></li>
			<li><a href="#slide-2" id="Slide02"><span></span></a></li>
			<li><a href="#slide-3" id="Slide03"><span></span></a></li>
			<li><a href="#slide-4" id="Slide04"><span></span></a></li>
			<li><a href="#slide-5" id="Slide04"><span></span></a></li>
		</ul>
	</nav>


<div class="slides-container">
	<div class="slide active" id="slide-1">
		<div id="" class=" centered">
		<h1>What´s up?</h1>
		<p class="">Inspiriert von den Cartoons<br>des Künstlers 
		<a href="http://www.perjovschi.ro" target="blank">Dan Perjovschi</a></p>
		</div>
	</div>
	<div class="slide" id="slide-2">
		<div class="cover">
			
		<svg class="centered" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="604" height="649.4" viewBox="0 0 604 649.4" version="1.1">

		<style>.s0{fill:none;stroke-width:8;stroke:#000;}.s1{fill:none;stroke-width:10.3;stroke:#000;}.s2{fill:#000;}.s3{fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:6.6;stroke:#000;}.s4{fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:6.1;stroke:#000;}.s5{fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:5.4;stroke:#000;}.s6{fill:none;stroke-width:6.6;stroke:#000;}.s7{fill:none;stroke-linecap:round;stroke-width:8;stroke:#000;}</style>

		<g transform="translate(-54.285711,-262.6479)"><path d="m163.8 516.5 63.4-4.1-8.6 32.9-61.4 0 10-35.7 0 0 1.4 1.4M288.6 603.8c1.9 28.7 4.3 57.8 10 82.9 8.5 29.6 17.7 57.9 30 80 0 0 46.9-11.8 65.7-20 71-30.9-67.1-155.7-67.1-155.7z" class="s0"/>

		<g transform="matrix(-0.73167327,0.6816555,0.6816555,0.73167327,117.50684,-51.004864)"/>
		<path  d="m358.6 640.9c-41.4 17.3-77.8 23.7-119.2 18.2m-1.2 28.4c40.3-1.4 83.6-4.7 123.9-24.1" class="s0"/>
		<path id="hand01" d="m238.6 655.2-14.3 1.4-27.2-13c-11.1 6.9-2.7 15.9 15.6 25.6l0.9 11.4 2.2 1.7 25.7 10-2.9-37.1" style="fill:#000;stroke:#000"/>

		<path id="hand02" d="m238.6 655.2-14.3 1.4-13-0.1c-3.3 11.9-7 0.2 1.3 12.7l0.9 11.4 2.2 1.7 25.7 10-2.9-37.1" style="fill:#000;stroke:#000"/>

		<path d="M332.86 762.36 330 886.65" id="path5139"  class="s0"/>
			<path d="m357.14 756.65c0.42 47.35-1.47 105.41 5.71 125.71" id="path5141" class="s0"/>
			<path d="m390 745.22c-7.75 48.81 0.33 112.08-2.86 137.91" id="path5143" class="s0"/>
			<path d="m414.29 710.93c7.19 68.81 5.58 122.95 1.43 172.86" id="path5145" class="s0"/>

		<path d="M92.9 896.6 285.7 885.2c122.9 1 240.8 11.7 368.6 2.9l0 0M202.9 363.8l-4.3 35.7 0 137.1L210 885.2l-4.3 21.4 0 1.4M582.9 269.5l1.4 421.4 1.4 41.4-1.4 135.7 0 0" class="s0"/><path d="m155.7 548.1 1.4 145.7c0 0-7.1 22.9 1.4 22.9 8.6 0 50-10 50-10l0 0" style="fill:none;stroke-width:7;stroke:#000"/><path d="m188.6 583.8 0 20 0 0" style="fill:none;stroke-width:12;stroke:#000"/><path d="m171.4 613.6 0 14.6 0 0M185.7 615l0 14.6 0 0M171.4 630.8l0 14.6 0 0M187.1 632.2l0 14.6 0 0M172.9 650.8l0 14.6 0 0M187.1 649.3l0 14.6 0 0" class="s1"/><path d="m101.4 573.8a23.6 37.1 0 1 1-47.1 0 23.6 37.1 0 1 1 47.1 0z" fill="none"/><path d="m537.1 330.9c49.1 28.9 54.2 7.2 54.3 7.1" class="s0"/>

		<g id="kamera">
		<path d="m491.4 316.6-22.9 15.7c2 12.5 3.2 25.8 38.6 8.6m-18.6-41.4 22.9 45.7 61.4-30-24.3-48.6-54.3 40 0 0" class="s0"/>
		<path transform="matrix(1.1092116,0,0,1.0179227,-244.06769,-39.239385)" d="m661.4 373.1a14.3 12.1 0 1 1-28.6 0 14.3 12.1 0 1 1 28.6 0z" fill="#000"/>
		</g>

		<g id="text">
		<path d="m367.7 554.1-3.3-31.5c14.7-9 22.6 3.4 6.6 16.6" class="s3"/><path d="m269.1 454.5 15.3 8.7 1.1 0" class="s4"/><path d="m289.2 437.1-7 37.5" class="s3"/><path d="m296.1 445c-1.9 8.6-8.9 20.9 6.6 19.7 11.7-28.9-2.4-17.1-6.6-19.7zM316.1 437c-5.7 32.7 18 24.7 15.3-2.2" class="s4"/><path d="m319.8 488.2 0.7-22.8c6.7-1 24.1-9.6 7.6 11.4l9.5 6.9M353.6 457.1c-18.1 4.1-17.1 30.9 0.8 24.9M343.7 473.6c9.1-6.3 10.8-1.7 10.8-1.7" class="s3"/><path d="m361.1 480.3 2.5-25.7 5.8 11.6 5.8-13.3 4.1 19.1 0 0" style="fill:none;stroke-linejoin:round;stroke-width:6.6;stroke:#000"/><path d="m399 440.7c0 0-12.1 1.8-12.9 8.1 3.2 25.6 5.3 21.5 17 16.3M389.2 458c7.5-3.4 8.8-1.4 8.8-1.4" class="s5"/><path d="m406.7 460.4 0.8-25.7 6.6 9.9 2.5-14.1 9.1 20.7" class="s3"/><path d="m435.5 451.8-7.6-28.9c5.3-1.1 14.8-2.7 10.8 13.4 7.9 10.8 11.5 12.5 1 13.3" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:7.4;stroke:#000"/><path d="m463.9 414-14.1 7.5c-2.8 17.6 4.7 31 15.8 19.9" class="s6"/><path d="m453.7 434.8c7.5-3.4 8.8-1.4 8.8-1.4" class="s5"/><path d="m464.7 440.5c4.6-36.8 12.7-31 8.3-13.3 1.7 5.9-3.5 12.8 13.3 5.8" class="s6"/><path d="m357.5 511.6 1-25.2 10.2 14.6 9.9-20.5 0.9 26.6" class="s3"/><path d="m389 480.3c0 0 3.7 23.4 9.4 11.1 5.7-12.3 7-19 7-19l-6 32.6" style="fill:none;stroke-linejoin:round;stroke-width:5.7;stroke:#000"/><path d="m396.7 516.8c0.6 9.7 2.1 19.3-5.8 29M405 544.1l6.6-26.5 6.6 19.1 12.4-26.5M450.6 487.7c18.1-6.2 24.2-6.8 0 30.7l0 0.8" class="s3"/><path d="m448.1 532.5 2.5-0.8 1.7-2.5" class="s6"/></g><g transform="translate(-49.201297,-269.1897)">
		</g>
		<path id="kopf02" d="m291.4 606.6c-19.5 8.4-48.6-70-48.6-70l74.3-5.7-28.6 27.1c0 0 73.8 18 2.9 48.6z" class="s0"/>
		<path id="mund03" transform="matrix(0.82314845,-0.20579891,0.20579891,0.82314845,-252.98321,153.28523)" d="m534.3 643.1a23.6 15 0 1 1-47.1 0 23.6 15 0 1 1 47.1 0z" fill="#000"/>

		</g>
		<path id="kopf" d="m291.4 606.6c-19.5 8.4-48.6-70-48.6-70l74.3-5.7-28.6 27.1c0 0 73.8 18 2.9 48.6z" transform="matrix(-0.73167327,0.6816555,0.6816555,0.73167327,63.221129,-313.65276)" class="s0"/>
		<path id="mund01" d="m222.7 319.1c10.4 3.6 19.1-2.6 24.2-3" class="s7"/>
		<path id="mund02" d="m223.2 323.6c7.7-8 17.9-13.1 24.2-8.1" class="s7"/></g>
		</svg>
		</div>
		<div class="againPIN">Again ?</div>    
	</div>
<!-- ============  ME =========================================  -->
	<div class="slide" id="slide-3">
		<div class="cover">
			<div class="wrapME centered">
			<svg class="me centered" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="584.3" height="345.7" viewBox="0 0 584.3 345.7" version="1.1">
				<g transform="translate(-65.4,-584.07647)">
				<path d="m70 908.1 60-265.7 17.1-41.4c18.6 99.4 40.5 194.3 67.1 282.9l31.3-68.6 80.1-215.7 8.4 224.2 10.2 101.5 0-1.4" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:9.2;stroke:#000"/>
				<path id="ME" d="m390 779.5c0 0 43-9.2 64.3-5.8 20.4 3.2 168.5 0.1 168.5 0.1l0 0m10-185.7c0 0-35.5 6.5-74.3 3.9-38.8-2.6-175.7 4.7-175.7 4.7 0 0 6.6 43.9 4.7 65.8-7.4 85.6 5.3 261.4 5.3 261.4l160-1.4 77.2-2.5 15.7 1.1 0 0" style="fill:none;stroke-linecap:round;stroke-width:8;stroke:#000"/>
				<path id="ME02" class="hidden" d="m390 779.5c0 0 43-9.2 64.3-5.8 20.4 3.2 168.5 0.1 168.5 0.1l0 0m10-185.7c0 0-35.5 6.5-74.3 3.9-38.8-2.6-175.7 4.7-175.7 4.7 0 0 6.6 43.9 4.7 65.8-7.4 85.6 5.3 261.4 5.3 261.4 0 0 29.1-49.1 55.4-34.7 75.9 41.8 105.1 33.7 104.6 33.2l77.2-2.5 15.7 1.1 0 0" style="fill:none;stroke-linecap:round;stroke-width:8;stroke:#000"/>
				</g>
  <g id="YOU" class="you" transform="matrix(0.92836602,0,0,0.91107136,22.786008,31.768882)" >
    <path d="m 350.8,313.5 c -2.8,9 11.1,22.2 12.2,19.7 m 4.3,-20.6 c -0.5,13.7 -4.6,20.5 -8.7,32.4" />
    <path d="m 381.4,313 c -4.2,-1.3 -8.1,13.6 -4.5,17 4.3,4.3 8.9,-3.1 8.9,-3.1 0.1,0.1 2.6,-11.9 -4.4,-14 z" />
    <path d="m 400,313.2 c -4.5,5.6 -11.3,27.7 2.9,23.6 m 6.4,-18.2 0,0 c -2.4,6.6 -5.4,13 -3.2,21.4 l 1.8,1.4" />
  </g>
  

			</div>
		</div>
		<div class="againME">Again ?</div> 
	</div>
<!-- ============  GreenAttack =========================================  -->
  <div class="slide" id="slide-4">
		<div class="cover">
		<svg id="greenattack" class="centered" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="752" height="430" viewBox="0 0 752 430" version="1.1">
		
		<path class="greenattack" d="m2 369.4c44.2-5.7 84 3.1 126.3 3 23.2 0.7 40.6-0.4 62.6-1 24.1-6.9 51.6 2 77.1 1 37.7-0.2 79 1.2 111.8-8.1 20.8-0.4 41.5-1.5 62.6-1 26.3-0.5 53 1.1 78.8-1 14.6-2.5 30.2 0.8 44.4-4 45.6-1.5 89.7 2.6 130.8-4 17 0 34 0 51 0l-1 0" />
		<path class="panzer greenattack" d="m387.9 226.9c85.5 3.4 125.2 7.1 163.1 62.7 9 98.4-310.8 108.3-305 29.2 3.4-69.2 80.2-79.2 142.8-93.7" />
		<path class="sonne greenattack" d="m56.6 38.1c20.4 30.9 23 20.9 23.2 20.7M114.7 30.7 114.7 30.7c-6.9 14.7-0.3 18 0 18.2M181.9 44.1c-30.8 29.4-34.2 21.4-34.3 21.2M143.4 100.7c35.9 30 33.3 36.3 33.3 36.4M97 134c-16.2 13.6-26.7 31.5-28.3 32.3M65.7 107.3C22.3 111.5 19.2 104.2 19.2 104.2M90.9 84.5c13.9-20.7 24-14.9 34.3-9.1 10.4 5.8 6 36.9-23.2 32.3C90.7 106 85.1 87.2 93.9 74.4"/>
		
		<path class="panzer greenattack" d="m365.8 230.4c-8.1-17.3-7.6-36-0.9-55.7 126.6-29.4 98 65.3 42.4 51.3M276.4 173l63.6-49.5 74.6 18.6 0 0M276.4 173l63.6-49.5 74.6 18.6 0 0M351.1 130.6 293 183.6 366.7 133.2l-65.4 53.9M384.2 136.8l-72.8 55.7M397.1 139.4 320.7 197.7 333.6 134.1l61.7 28.3M406.4 145.6l-75.6 67.2-50.7-40.6M324.4 142.1l47.9 28.3M312.4 151.8l46.1 26.5M301.3 160.6l48.8 28.3M293 167.7l44.2 28.3" />

		<g class="" transform="translate(0.00132601,-1.0489993)">
		<path class="rohr01 greenattack" d="m456.1 182.7 42.4-1.1 91.2-2.3c16.8-1.9 23-3.2 35.1-2.8M441.4 220.7 441.4 220.7c21.7-2.4 43.5-4.7 65.2-7.1 49.2-9.5 83.3-10.3 120.9-13.2" />
		<path class="rohr01 greenattack" d="m617.7 174.1c11.9-1.3 22.7 25.4 4.9 28.7-17.9 3.2-16.8-27.4-4.9-28.7z"/></g>

    <path id="wolke"
       style="fill:#5d5d5d;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
       d="m 310.11683,42.101423 c -0.36044,-52.354665 39.99112,-26.815659 62.62946,-23.233509 58.40704,-38.0038 59.04262,-12.9841793 59.599,12.121831 142.96931,13.954955 70.1326,64.649839 26.26397,57.578694 2.41337,36.889581 -44.84618,35.832871 -90.91373,8.081221 -90.72834,33.39258 -67.8205,8.24532 -75.76144,-1.010153 -21.27206,-17.886896 -20.13776,-38.422833 18.18274,-53.538084 z" />
		
		<path id="kugel" class="greenattack kugel"  d="m616.5 184.4c6.4-9.8 11-7.1 15.8-4.3 4.8 2.8 2.7 17.6-10.7 15.4-5.2-0.8-7.8-9.8-3.7-15.9"/>
		</svg>
			
		</div>
		<div class="againGreenAttack">Again ?</div> 

  </div>
<!-- ============  HELMUT =========================================  -->
  <div class="slide" id="slide-5">
		<div class="cover">
		<svg class="helmut centered" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="686.7" height="417.6" viewBox="0 0 686.7 417.6" version="1.1">
		<style>.s0{fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:12;stroke:#000;}</style>

		<g transform="translate(-24.277166,-12.714294)">
		<path class="typo s0" d="m36.4 194c-2.4 49.2-6.5 61.2-6.1 61.6 3.4 55.2 13.2 121.3 4 168.7l0 0M36.4 303.1l82.8-1 0 0 0 0M122.2 193c-0.7 36.5-3.8 77.6-2 109.1 0 0 3.1 36.3 4 54.5 1.1 21.2 3.7 44 2 63.6M165.7 187l4 230.3 65.7 2 0 0M171.7 195.1l54.5-4 10 0M272.7 192c6.3 80.9 12.2 161.4 8.1 229.3l47.5-2M377.8 422.3c-9.4 13.2 0.4-139.1 3-229.3 16.2 54.5 24 114.5 48.5 163.6l32.3-163.6c2.7 75.8-1.2 154.8 8.1 227.3l0-1M498.1 187c-13.9 363 129.7 223.7 95.8 20.2M609 187.7l96-1M649 189.7c-12 88.6-0.7 154-1 231" />
		
		<path d="m171 287.7c11.1-0.9 121.3 0.5 131.1 0.1 18.3-0.9 14.7 21 0.8 19.5C289.4 305.9 187.9 309.7 173 309.7" style="fill:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:8;stroke:#000"/>
		<path d="m208 287.7 0 19" style="fill:none;stroke-width:12;stroke:#000"/>
<path class="typo s0" M609 187.7l96-1/>
		<path class="rauch" d="m331 18.7 3 27c-14.3 16.1-25.4 25.1-17 47 8.3 26 30.3 43.5-4 84-10.5 27.8-1.4 36.1 9 43 14.6 13.2 0.7 39.4-14 66" /></g>
		</svg>
			
		</div>
		<div class="againHELMUT">Again ?</div> 

  </div>
</div>
    

   
  </body>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/plugins/ScrollToPlugin.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/MorphSVGPlugin.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/mikeK/fullscreen-slides-vJNRPQ */
body, div, p {
    margin: 0;
    padding: 0;
}

body {
    font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
    font-weight: 300;
    letter-spacing: 0.0625em;
}

a {
    text-decoration: none;
    color: black;
    font-style: italic;
}
a:hover {
	color: #0D6708;
}
h1 {
	text-align: center;
    font-weight: 300;
    font-size: 3em;
}
nav {
    position: absolute;
    bottom: 0%;
    left: 50%;
	width: 240px;
    z-index: 100;
	visibility: hidden;
}

nav ul {
	margin: 0;
    padding: 0;
}

nav ul li {
    display: block;
    width: 14px;
    height: 13px;
    margin: 7px 2px 2px 40px;
	position: relative;
	float: left;
}

nav ul li:first-child {
    margin-left: 0;
}

nav a {
   display: block;
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    cursor: pointer;
    text-decoration: none;
   
}
nav  span {
    border-radius: 50%;
    position: absolute;
    z-index: 1;
    height: 4px;
    width: 4px;
    border: 0;
    background: black;
    left: 50%;
    top: 50%;
    margin: -2px 0 0 -2px;
    -webkit-transition: all 0.1s ease-in-out;
    -moz-transition: all 0.1s ease-in-out;
    -o-transition: all 0.1s ease-in-out;
    transition: all 0.1s ease-in-out;
}
a.active span {
    height: 16px;
    width: 16px;
    margin: -9px 0 0 -9px;
    border-radius: 100%;
}
 ul li:hover  span {
    height: 20px;
    width: 20px;
    margin: -13px 0 0 -9px;
    border-radius: 100%;
}


.slides-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 10;
}

.slide {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.slide .centered {
    position: absolute;
    width: 100%;
    top: 40%;
    left: 50%;
	visibility: hidden;
}

.slide .centered h1 {
  text-align: center; 
	margin: 0;
}

.slide .centered p {
    text-align: center;
    margin: 0;
    font-size: 15px;
}

#slide-1 {
    background-color: #FFFFFF;
}

#slide-2 {
    background-color: #45959b;
}

#slide-3 {
    background-color: #778899;
}

#slide-4 {
    color: #FFFFFF;
    background-color: #FFFFFF;
}
#slide-5 {
    color: #FFFFFF;
    background-color: #413257;
}
.go-prev, .go-next {
    cursor: pointer;
    font-weight: bold;
    text-decoration: underline;
}

.action {
	position: absolute;
	left:50%; top:50%;
	width: 200px !important; height: 200px;
	background: red;
}
.cover {
	width: 90vw;
    height: 50.625vw;
    max-height: 90vh;
    max-width: 160vh;
    margin: auto;
    margin-bottom: 20px;
    position: absolute;
    top: 7%;
    left: 0;
    right: 0;
}

.cover img {
	position: relative;
	width: 100%;
	height: auto;
}
svg {
	position: absolute;
    display: block;
    width: auto;
    height: 80%;
    overflow: visible;
}
#text, #kopf02, #mund02, #mund03, #hand01, .hidden {visibility: hidden;}


.wrapME {
	position: absolute;
	top: 27%;
	left: 11%;
  height: 75%;
	width: inherit;
	overflow: hidden;
}
.me {
	height: 85%;
  top: 58% !important;
}
#YOU {
	top: 89%;
    left: 55%;
    height: 8%;
}
.you {
	fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 8;
    stroke: #000;
}
#greenattack {width: 66%; overflow: hidden;}
.greenattack {
	fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 8px;
    stroke: #000;
}
.sonne {visibility: hidden; left:0%;}
.kugel {fill: black; visibility: hidden;}

#slide-5 .cover {
	overflow: visible;
}
.helmut {
	height: 44%;
	left: 4%;
}
.rauch {
	fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 12;
    stroke: #fff;
	visibility: hidden;
}

.close {
    position: absolute;
    top: -1px;
    right: 25px;
    font-size: 55px;
    font-weight: 300;
	color: #49D549;
    cursor: pointer;
    z-index: 1000;
}
.againPIN, .againME, .againHELMUT, .againGreenAttack {
    position: absolute;
    top: auto;
    bottom: 5%;
    right: 5%;
    color: #0D6708;
    cursor: pointer;
    visibility: hidden;
    z-index: 1000;
}

	
}

/*Downloaded from https://www.codeseek.co/mikeK/fullscreen-slides-vJNRPQ */


  //  =============  xxxxx  ==========================	

  TweenMax.set(".centered, nav", {autoAlpha: 1, xPercent:-50, yPercent:-50, force3D:true});	


  //Forked from [Chrysto](http://codepen.io/bassta/)'s Pen [Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin](http://codepen.io/bassta/pen/kDvmC/).  Optimized with the help of Blake Owen

  //First the variables our app is going to use need to be declared

  //References to DOM elements
  var $window = $(window);
  var $document = $(document);
  //Only links that starts with #
  var $navButtons = $("nav a").filter("[href^=#]");
  var $navGoPrev = $(".go-prev");
  var $navGoNext = $(".go-next");
  var $slidesContainer = $(".slides-container");
  var $allSlides = $(".slide");
  var $currentSlide = $allSlides.first();
  var slideControl = $("nav a")


  //Animating flag - is our app animating
  var isAnimating = false;

  //The height of the window
  var pageHeight = $window.innerHeight();

  //Key codes for up and down arrows on keyboard. We'll be using this to navigate change slides using the keyboard
  var keyCodes = {
    UP  : 38,
    DOWN: 40
  };


  var currentIndex = 0;
  
  var timeline1 = new TimelineLite()

	.reverse();
	
	
  var timeline2 = new TimelineLite()
    .to("#hand01", 0.5,{autoAlpha:1, repeat:3}, "+=0.5")  
    .to("#mund01", 0.5,{morphSVG:"#mund02"}, "+=0")
    .to("#kopf, #mund01", 1, {autoAlpha: 0}, "+=1")
    .to("#kopf02, #mund03", 1, {autoAlpha: 1}, "-=1")
    .to("#text", 1, {autoAlpha: 1}, "-=0.5")
    .to("#kamera", 1, {rotation:-20, transformOrigin:"50% 50%"}, "-=0.5")
    .to('.againPIN', 0.5, {autoAlpha: 1},"+=1")    
    .reverse();

	$(".againPIN").on("click", function() {
		timeline2.restart();
	});	
	
  
  var timeline3 = new TimelineLite({repeat:-1, yoyo: true,  repeatDelay:0.5})
    .to("#ME",2, {morphSVG:"#ME02", repeat:3, yoyo: true,  repeatDelay:0.5})
    .fromTo("#YOU",2, {y:"+110%"}, {y:"0%", repeat:3, yoyo: true,  repeatDelay:0.5},0.2)
    .to('.againME', 0.5, {autoAlpha: 1},"+=1") 
    .reverse();
	
	$(".againME").on("click", function() {
		timeline3.restart();
	});	

	
	var timeline4 = new TimelineLite()
	.set('.sonne', {autoAlpha: 1})
	.fromTo('.sonne', 4, {x:"-150%"}, {x:"+200%", scale: 0.4, ease: Power4.easeNone},0)
	.to('.sonne', 0.1, {autoAlpha: 0},"-=1")
	.to('#wolke', 4, {x:"+80%", ease: Power4.easeNone},"-=1")
	.to(".rohr01",0.07, {x:"-30px", repeat:9,  yoyo: true, repeatDelay:0.1, ease: Power4.easeIn},0.8)
	.to('.againGreenAttack', 0.5, {autoAlpha: 1},"+=1") 
    .reverse();

	$(".againGreenAttack").on("click", function() {
		timeline4.restart();
	});	
	
  var timeline5 = new TimelineLite()
    .set('.rauch', { autoAlpha:1}, "+=1")
    .to('.rauch', 3, { y: "-100%", scale:1.8, opacity:0, repeat: 3, repeatDelay: 1})
    .to('.againHELMUT', 0.5, {autoAlpha: 1},"+=1")
    .reverse();

	$(".againHELMUT").on("click", function() {
		timeline5.restart();
	});	 
	
  var timelines = [timeline1, timeline2, timeline3, timeline4, timeline5];
  
  //Going to the first slide
  goToSlide($currentSlide);
  //TweenLite.set($currentSlide, {className: "+=active"});

  /*
	*   Adding event listeners
	* */

	$window.on("resize", onResize).resize();
	$window.on("mousewheel DOMMouseScroll", onMouseWheel);
	$document.on("keydown", onKeyDown);
	$navButtons.on("click", onNavButtonClick);
	$navGoPrev.on("click", goToPrevSlide);
	$navGoNext.on("click", goToNextSlide);
	
  
  /*
	*   Internal functions
	* */


  /*
	*   When a button is clicked - first get the button href, and then slide to the container, if there's such a container
	* */
  function onNavButtonClick(event)
  {
    //The clicked button
    var $button = $(this);

    //The slide the button points to
    var $slide = $($button.attr("href"));

    //If the slide exists, we go to it
    if($slide.length)
    {
      goToSlide($slide);
      event.preventDefault();
    }
  }

  /*
	*   Getting the pressed key. Only if it's up or down arrow, we go to prev or next slide and prevent default behaviour
	*   This way, if there's text input, the user is still able to fill it
	* */
  function onKeyDown(event)
  {

    var PRESSED_KEY = event.keyCode;

    if(PRESSED_KEY == keyCodes.UP)
    {
      goToPrevSlide();
      event.preventDefault();
    }
    else if(PRESSED_KEY == keyCodes.DOWN)
    {
      goToNextSlide();
      event.preventDefault();
    }

  }

  /*
	*   When user scrolls with the mouse, we have to change slides
	* */
  function onMouseWheel(event)
  {
    //Normalize event wheel delta
    var delta = event.originalEvent.wheelDelta / 30 || -event.originalEvent.detail;

    //If the user scrolled up, it goes to previous slide, otherwise - to next slide
    if(delta < -1)
    {
      goToNextSlide();
    }
    else if(delta > 1)
    {
      goToPrevSlide();
    }

    event.preventDefault();


  }

  /*
	*   If there's a previous slide, slide to it
	* */
  function goToPrevSlide()
  {
    if($currentSlide.prev().length)
    {
      goToSlide($currentSlide.prev());
    }
  }

  /*
	*   If there's a next slide, slide to it
	* */
  function goToNextSlide()
  {
    if($currentSlide.next().length)
    {
      goToSlide($currentSlide.next());
    }
  }


  /*
	*   Actual transition between slides
	* */
  function goToSlide($slide)
  {
    //If the slides are not changing and there's such a slide
    if(!isAnimating && $slide.length)
    {
      //setting animating flag to true
      isAnimating = true;
      $currentSlide = $slide;
      NextSlide = $currentSlide.next()           

      //Sliding to current slide
      TweenLite.to($slidesContainer, 1, {scrollTo: {y: pageHeight * $currentSlide.index() }, onComplete: onSlideChangeEnd, onCompleteScope: this});

      //Definig slide status
      TweenLite.to($allSlides.filter(".active"), 0.1, {className: "-=active"});
      TweenLite.to($allSlides.filter($currentSlide), 0.1, {className: "+=active"});

      //Animating menu items
      TweenLite.to($navButtons.filter(".active"), 0.5, {className: "-=active"});
      TweenLite.to($navButtons.filter("[href=#" + $currentSlide.attr("id") + "]"), 0.5, {className: "+=active"});


    }
  }

  /*
	*   Once the sliding is finished, we need to restore "isAnimating" flag.
	*   You can also do other things in this function, such as changing page title
	* */
  function onSlideChangeEnd() {
    isAnimating = false;
    
    // Reverse the timeline for the previous slide
    timelines[currentIndex].reversed(true).progress(0);
    
    // Change the index
    currentIndex = $currentSlide.index();
    
    // Play the timeline for the current slide
    timelines[currentIndex].reversed(false);
  }

  /*
	*   When user resize it's browser we need to know the new height, so we can properly align the current slide
	* */
  function onResize(event)
  {

    //This will give us the new height of the window
    var newPageHeight = $window.innerHeight();

    /*
		*   If the new height is different from the old height ( the browser is resized vertically ), the slides are resized
		* */
    if(pageHeight !== newPageHeight)
    {
      pageHeight = newPageHeight;

      //This can be done via CSS only, but fails into some old browsers, so I prefer to set height via JS
      TweenLite.set([$slidesContainer, $allSlides], {height: pageHeight + "px"});

      //The current slide should be always on the top
      TweenLite.set($slidesContainer, {scrollTo: {y: pageHeight * $currentSlide.index() }});
    }

  }

Comments