JSFiddle - React, Tailwind, and code Playground
by Ahmad Baktash Hayeri
HTML
<div class="container">
<div class="cards">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">3</div>
</div>
</div>
CSS
.container {
width:310px;
height: 100px;
border: 2px solid black;
overflow: hidden;
}
.card {
float:left;
height: 100px;
width: 100px;
background-color:blue;
box-sizing: border-box;
border: 1px solid red;
color: white;
font-size: 23px;
}
.cards:hover {
transform: translateX(-100px);
transition-duration: 3s;
animation-duration: 3s;
animation-fill-mode: forwards;
}
JavaScript
$(function () {
var $container = $('.container');
$container.on('mouseenter', function (e) {
e.preventDefault();
var $cards = $('.card');
var $tempCard = $($cards[0]).clone();
$('.cards').append($tempCard);
var width = $cards.width();
$cards.width(width + 100);
});
$container.on('mouseleave', function (e) {
e.preventDefault(); return false;
var $cards0 = $('.card');
console.log($cards0.length);
$cards0.eq($cards0.length - 1).remove();
});
});