I am not sure if this is possible. Today I have 5 DIV, and after clicking on it, the jQuery number will check the number of clicked and fadeIn()or the fadeOut()number of fields.
What I want to do is that when the boxes move (due to display: flexand justify-content: space-around), they have a smooth transition.
I tried to do this with a css transition, but it did not work.
Can anybody help me?
Here is the JSFiddle: https://jsfiddle.net/0k1xj3d5/1/
HTML:
<div class="wrapper">
<div class="num" rel="1">1</div>
<div class="num" rel="2">2</div>
<div class="num" rel="3">3</div>
<div class="num" rel="4">4</div>
<div class="num" rel="5">5</div>
</div>
<div class="wrapper">
<div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3"></div>
<div class="box-4"></div>
<div class="box-5"></div>
</div>
CSS
.wrapper {
display: flex;
justify-content: space-around;
margin-bottom: 50px;
}
[class^=box] {
width: 50px;
height: 50px;
background-color: blue;
}
.num {
width: 50px;
height: 50px;
background-color: green;
}
JQuery
$('.num').on('click', function(){
var quant = $(this).attr('rel');
for(var i=1; i<=5 ;i++){
if(i <= quant){
if(!$('.box-' + i).is(':visible')){
$('.box-' + i).fadeIn();
}
} else {
$('.box-' + i).fadeOut();
}
}
});
source
share