JSFiddle - React, Tailwind, and code Playground
HTML
<div class="move left">←</div>
<div class="move right">→</div>
<div id="container">
<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>
</div>
CSS
body {
padding: 0px;
}
#container {
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
}
.box {
position: absolute;
width: 50%;
height: 300px;
line-height: 300px;
font-size: 50px;
text-align: center;
border: 2px solid black;
left: 150%;
top: 100px;
margin-left: -25%;
-webkit-transition: all 0.3s ease-out;
/* Chrome 1-25, Safari 3.2+ */
-moz-transition: all 0.3s ease-out;
/* Firefox 4-15 */
-o-transition: all 0.3s ease-out;
/* Opera 10.50–12.00 */
transition: all 0.3s ease-out;
/* Chrome 26, Firefox 16+, IE 10+, Opera 12.10+ */
}
#box1 {
background-color: green;
left: 50%;
}
#box2 {
background-color: yellow;
}
#box3 {
background-color: red;
}
#box4 {
background-color: orange;
}
#box5 {
background-color: blue;
}
.move {
position:fixed;
z-index:2;
top:50%;
margin-top:-20px;
text-align:center;
padding:20px;
background:#fff;
color: #000;
}
.left {
left:0;
}
.right {
right:0;
}
JavaScript
var boxes = $(".box").get(),
current = 0;
$('.right').click(function () {
if (current == (-boxes.length + 1)){
} else {
current--;
updateBoxes();
}
console.log(-boxes.length + 1);
console.log(current);
});
function updateBoxes() {
for (var i = current; i < (boxes.length + current); i++) {
boxes[i - current].style.left = (i * 100 + 50) + "%";
}
}
$('.left').click(function () {
if (current == 0){
}else{
current++;
updateBoxes();
}
});