JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="main">
<div class="box">
<div class="box__inner box__inner_color_red" style="background-color: red;"></div>
</div>
<div class="box">
<div class="box__inner box__inner_color_orange" style="background-color: orange;"></div>
</div>
<div class="box">
<div class="box__inner box__inner_color_blue" style="background-color: blue;"></div>
</div>
<div class="box">
<div class="box__inner box__inner_color_green" style="background-color: green;"></div>
</div>
<div class="box">
<div class="box__inner box__inner_color_black" style="background-color: black;"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.js"></script> -->
<script src="main.js"></script>
</body>
</html>
CSS
*,
*::after,
*::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.main {
display: flex;
width: 800px;
margin: 100px auto;
padding: 10px;
border: 1px solid #000;
z-index: 1;
}
.box {
position: relative;
width: 150px;
height: 150px;
margin-right: 10px;
}
.box:last-child {
margin-right: 0;
}
.box:last-child::after {
margin-right: 0;
}
.box:nth-child(1) {
background-color: red;
}
.box:nth-child(2) {
background-color: orange;
}
.box:nth-child(3) {
background-color: blue;
}
.box:nth-child(4) {
background-color: green;
}
.box:nth-child(5) {
background-color: black;
}
.box__inner {
position: absolute;
top: 0px;
left: 0px;
width: 148px;
height: 150px;
cursor: pointer;
z-index: 2;
}
.box__inner_color_red {
background-color: red;
}
.box__inner_color_orange {
background-color: orange;
}
.box__inner_color_blue {
background-color: blue;
}
.box__inner_color_green {
background-color: green;
}
.box__inner_color_black {
background-color: black;
}
JavaScript
$('.box__inner').click(function () {
$(this).css('z-index', '100')
if (this.style.backgroundColor == 'red') {
$(this).animate({
top: 17,
left: 164,
width: '450px',
height: '450px',
});
}
else if (this.style.backgroundColor == 'orange') {
$(this).animate({
top: 17,
left: (164 - 158),
width: '450px',
height: '450px',
});
}
else if (this.style.backgroundColor == 'blue') {
$(this).animate({
top: 17,
left: (164 - (158 * 2)),
width: '450px',
height: '450px',
});
}
else if (this.style.backgroundColor == 'green') {
$(this).animate({
top: 17,
left: (164 - (158 * 3)),
width: '450px',
height: '450px',
});
}
else if (this.style.backgroundColor == 'black') {
$(this).animate({
top: 17,
left: (164 - (158 * 4)),
width: '450px',
height: '450px',
});
}
});