JSFiddle - React, Tailwind, and code Playground
HTML
<div id="fourth" class="page hidden">Fourth page
<button id="button1" >First page</button>
</div>
<div id="third" class="page hidden">Third page - some content</div>
<div id="second" class="page hidden">Second page - some content</div>
<div id="first" class="page">First page - some content
<button id="button2">Second page</button>
</div>
CSS
@charset "utf-8";
body {
background-color: #fff;
margin: 0;
padding: 0;
overflow: hidden;
}
.page{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
#first {
color: #fff;
box-shadow: 0 0 40px #333;
background-color: #000;
}
#second {
position: absolute;
top: 0;
background-color: green;
}
#third {
background-color: red;
}
#fourth {
background-color: blue;
}
.hidden {
display: none;
}
.test {
-webkit-animation: wat 1s 1 ease-out normal;
-moz-animation: wat 1s 1 ease-out normal;
z-index: 100;
display: block;
}
.previous{
z-index: 99;
}
@-moz-keyframes wat {
0% {margin-left:-3000px;}
60% {margin-left: 200px;}
100% {margin-left: 0;}
}
@-webkit-keyframes wat {
0% {margin-left:-3000px;}
60% {margin-left: 200px;}
100% {margin-left: 0;}
}
JavaScript
$('#button1').click(function(){ gotoPage('first'); });
$('#button2').click(function(){ gotoPage('second'); });
var $previous, $current;
function gotoPage(id){
if($previous) $previous.removeClass('previous');
$previous = $current;
if($previous) $previous.removeClass('test').addClass('previous');
$current = $('#' + id).addClass('test').removeClass('hidden');
}
$(document).keyup(function(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch (KeyID) {
case 49:
gotoPage('first');
break;
case 50:
gotoPage('second');
break;
case 51:
gotoPage('third');
break;
case 52:
gotoPage('fourth');
break;
}
});
function pause(){
}