JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<div class="cards">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">3</div>
<div class="card">4</div>
<div class="card">5</div>
<div class="card">6</div>
</div>
</div>
CSS
.container {
width:300px;
height: 100px;
border: 2px solid black;
}
.cards {
overflow: hidden;
height: 100px;
white-space: nowrap;
position:relative;
}
.card {
height: 100px;
width: 100px;
background-color:blue;
box-shadow: inset 0 0 0 2px #F00;
color: white;
font-size: 23px;
left:-200px;
-webkit-transition: all .2s ease-out;
-moz-transition: all .2s ease-out;
-o-transition: all .2s ease-out;
transition: all .2s ease-out;
position: absolute;
display: block;
top: 0;
}
.card:nth-of-type(1) {
left: -100px;
}
.card:nth-of-type(2) {
left: 0px;
}
.card:nth-of-type(3) {
left: 100px;
}
.card:nth-of-type(4) {
left: 200px;
}
.card:nth-of-type(5) {
left: 300px;
}
.card:nth-of-type(6) {
left: 400px;
}
JavaScript
document.querySelector('.cards').addEventListener('mousedown', function (e) {
if (e.clientX < (this.offsetWidth >> 1)) { this.appendChild(this.removeChild(this.firstElementChild));
} else {
this.insertBefore(this.lastElementChild, this.firstElementChild);
}
});