1
I own 5 divs
forming a column.
I want that when I hover the mouse over one of the columns this column increases the width by 4% and the others become the size of 19%, causing an accordion effect.
I managed to do it with jQuery, but he has one delay on first use, causing you to "blink" the image when superimposed mouse.
I had already noticed this kind of flaw in another project, but in this one I’m not finding a solution with CSS to solve.
$(".col").mouseleave(function(){
var largura = $(document).width();
if(largura>420){
$(this).css("-webkit-transition","300ms");
enter = $(this).attr("class");
$(".col").each(function (){
if($(this).attr("class") != enter){
$(this).css("width","20%");
}
});
$(this).css("width","20%");
$(this).css("filter","grayscale(100%)");
}
});
$(".col").mouseenter(function(){
var largura = $(document).width();
if(largura>420){
$(this).css("-webkit-transition","900ms");
$(this).css("filter","grayscale(0%)");
enter = $(this).attr("class");
$(".col").each(function (){
if($(this).attr("class") != enter){
$(this).css("width","19%");
}
});
$(this).css("width","24%");
}
});
.col{
width: 20%;
min-height: 678px;
height: 100%;
float: left;
position: relative;
filter: grayscale(100%);
}
.col-vestibular{
background-image: url(../img/PSP-1366.png);
background-size: auto 768px;
/*adicionado para faciltar a visualização*/
background-color: #ccc;
}
.col-enem{
background-image: url(../img/PSP-1366.png);
background-size: auto 768px;
/*adicionado para faciltar a visualização*/
background-color: #c3c;
}
.col-transferencia{
background-image: url(../img/PSP-1366.png);
background-size: auto 768px;
/*adicionado para faciltar a visualização*/
background-color: #cc3;
}
.col-segunda-graduacao{
background-image: url(../img/PSP-1366.png);
background-size: auto 768px;
/*adicionado para faciltar a visualização*/
background-color: #3cc;
}
.col-pos-graduacao{
background-image: url(../img/PSP-1366.png);
background-size: auto 768px;
/*adicionado para faciltar a visualização*/
background-color: #c33;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="col col-enem" style="width: 20%; transition: 300ms; filter: grayscale(100%);">
</div>
<div class="col col-vestibular" style="width: 20%; transition: 300ms; filter: grayscale(100%);">
</div>
<div class="col col-segunda-graduacao" style="transition: 300ms; filter: grayscale(100%); width: 20%;">
</div>
<div class="col col-transferencia" style="width: 20%; transition: 300ms; filter: grayscale(100%);">
</div>
<div class="col col-pos-graduacao" style="width: 20%; transition: 300ms; filter: grayscale(100%);">
</div>
</div>
Why don’t you use the pseudo element Hover? I made one Fiddle very basic example.
– Marconi
The problem is that I need to grow this element and reduce the size of the others with the same effect as Hover, you know?
– Rafael Pessoa
I tested it here and it doesn’t blink. Give it a shot: https://jsfiddle.net/a23Lvnmc/
– Sam
It is possible to do this only with CSS, pseudo element Hover and flexbox. It gives a flexbox read that is very easy.
– dsantoro
Another tip would be to pre-load the image, I just don’t know if it works efficiently:
body::after{position:absolute;width:0;height:0;overflow:hidden;z-index:-1;content:url(../img/PSP-1366.png);}

– Sam
Look at this pen: It will save you: https://codepen.io/dsantoro/pen/mpyjMb
– dsantoro