JSFiddle - React, Tailwind, and code Playground
by jonigiuro
HTML
<div id="wrapper">
<ul id="controls">
<li class="control prev"><a href="#">Previous</a></li>
<li class="control next"><a href="#">Next</a></li>
</ul>
<div id="slides">
<div class="page slide1 is-current" data-index="0">
<h2>Slide1</h2>
</div>
<div class="page slide1 is-right" data-index="1">
<h2>Slide2</h2>
</div>
<div class="page slide1 is-right" data-index="2">
<h2>Slide3</h2>
</div>
</div>
</div>
CSS
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-o-box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
top: 0;
left: 0;
padding: 0;
margin: 0;
overflow: hidden;
background: #DDD;
font-family: Helvetica, Arial, Verdana;
}
#wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#controls {
width: 90%;
list-style: none;
margin: 10px auto;
padding: 10px;
background: white;
overflow: hidden;
z-index: 999;
}
.control {
display: block;
float: left;
width: 45%;
text-align: center;
}
.control a {
display: block;
color: white;
background: yellowgreen;
padding: 10px;
}
.control a:hover {
background: rgba(210, 185, 95, .2);
color: yellowgreen;
}
.prev {
margin-right: 10%;
}
#slides {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
overflow: hidden;
}
.page {
position: absolute;
top: 0;
width: 100%;
height: 100%;
padding: 20px;
padding-top: 80px;
-webkit-transition: left 500ms ease;
-moz-transition: left 500ms ease;
-o-transition: left 500ms ease;
transition: left 500ms ease;
}
.page.is-current {
left: 0;
}
.page.is-right {
left: 100%;
}
.page.is-left {
left: -100%;
}
JavaScript
var TransitionSlides = function() {
this.settings = {
left: $('.prev'),
right: $('.next'),
index: 0
};
this.init = function() {
var self = this;
this.settings.left.on('click', function() {
if(self.settings.index >= 1) {
self.slideLeft();
}
});
this.settings.right.on('click', function() {
if(self.settings.index <= 1) {
self.slideRight();
}
});
}
this.slideLeft = function() {
var self = this;
$('.is-current').addClass('is-right');
$('.page').removeClass('is-current');
self.settings.index = self.settings.index - 1 % 3;
$('.page').eq(self.settings.index).removeClass('is-left').removeClass('is-right').addClass('is-current');
}
this.slideRight = function() {
var self = this;
$('.is-current').addClass('is-left');
$('.page').removeClass('is-current');
self.settings.index = self.settings.index + 1 % 3;
$('.page').eq(self.settings.index).removeClass('is-left').removeClass('is-right').addClass('is-current');
}
this.init();
}
var transitionSlides = new TransitionSlides();