JSFiddle - React, Tailwind, and code Playground

by Nick Hulea

HTML

<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: 50%;
    top: 100px;
    margin-left: -25%;
}

#box1 {
    background-color: green;
    left: -50%;
}

#box2 {
    background-color: yellow;
}

#box3 {
    background-color: red;
    left: 150%;
}

#box4 {
    background-color: orange;
    left: 150%;
}

#box5 {
    background-color: blue;
    left: 150%;
}

JavaScript

$('.box').click(function() {
    $('.box').each( function() {
        if ($(this).offset().left < 0) {
            $(this).css("left", "150%");
        }
    });

    $(this).animate({
         left: '-50%'
     }, 500);
 
     if ($(this).next().size() > 0) {
         $(this).next().animate({
             left: '50%'
         }, 500);
     } else {
         $(this).prevAll().last().animate({
             left: '50%'
         }, 500);
     }
});