我有一组不断增长/收缩的flex项目:悬停我的问题是,即使我指定每一个都有自己的转换时间,它们都需要相同的时间来完成它们的动画。
是否可以修复这个问题,或者我必须使用"display: block“并手动编码每个元素的大小?
<flex>
<div class="item bg1" id="item-0"></div>
<div class="item bg2" id="item-1"></div>
<div class="item bg3" id="item-2"></div>
<div class="item bg4" id="item-3"></div>
<div class="item bg5" id="item-4"></div>
<div class="item bg6" id="item-5"></div>
<div class="item bg7" id="item-6"></div>
</flex>body {
margin: 0;
overflow: hidden;
}
flex {
margin-left: -5vw;
display: flex;
width: 110vw;
height: 100vh;
transform: skew(-10deg);
}
.item {
flex: 1;
}
.item:hover {
flex-grow: 3;
max-width:45vw;
}
.bg1 {
background: #442C59;
}
.bg2 {
background: #844270;
}
.bg3 {
background: #DC9A95;
}
.bg4 {
background: #BEC976;
}
.bg5 {
background: #CDCA98;
}
.bg6 {
background: #B04127;
}
.bg7 {
background: #6B4A4B;
}// ITEM 0
$("#item-0").mouseover(function(){
$(this).css({ transition: 'all 1s' });
$("#item-1").css({ transition: 'all 1.2s' });
$("#item-2").css({ transition: 'all 1.4s' });
$("#item-3").css({ transition: 'all 1.6s' });
$("#item-4").css({ transition: 'all 1.8s' });
$("#item-5").css({ transition: 'all 2s' });
$("#item-6").css({ transition: 'all 2.2s' });
});
// ITEM 1
$("#item-1").mouseover(function(){
$("#item-0").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
$("#item-2").css({ transition: 'all 1.2s' });
$("#item-3").css({ transition: 'all 1.4s' });
$("#item-4").css({ transition: 'all 1.6s' });
$("#item-5").css({ transition: 'all 1.8s' });
$("#item-6").css({ transition: 'all 2s' });
});
// ITEM 2
$("#item-2").mouseover(function(){
$("#item-0").css({ transition: 'all 1.4s' });
$("#item-1").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
$("#item-3").css({ transition: 'all 1.2s' });
$("#item-4").css({ transition: 'all 1.4s' });
$("#item-5").css({ transition: 'all 1.6s' });
$("#item-6").css({ transition: 'all 1.8s' });
});
// ITEM 3
$("#item-3").mouseover(function(){
$("#item-0").css({ transition: 'all 1.6s' });
$("#item-1").css({ transition: 'all 1.4s' });
$("#item-2").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
$("#item-4").css({ transition: 'all 1.2s' });
$("#item-5").css({ transition: 'all 1.4s' });
$("#item-6").css({ transition: 'all 1.6s' });
});
// ITEM 4
$("#item-4").mouseover(function(){
$("#item-0").css({ transition: 'all 1.8s' });
$("#item-1").css({ transition: 'all 1.6s' });
$("#item-2").css({ transition: 'all 1.4s' });
$("#item-3").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
$("#item-5").css({ transition: 'all 1.2s' });
$("#item-6").css({ transition: 'all 1.4s' });
});
// ITEM 5
$("#item-5").mouseover(function(){
$("#item-0").css({ transition: 'all 2s' });
$("#item-1").css({ transition: 'all 1.8s' });
$("#item-2").css({ transition: 'all 1.6s' });
$("#item-3").css({ transition: 'all 1.4s' });
$("#item-4").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
$("#item-6").css({ transition: 'all 1.2s' });
});
//ITEM 6
$("#item-6").mouseover(function(){
$("#item-0").css({ transition: 'all 2.2s' });
$("#item-1").css({ transition: 'all 2s' });
$("#item-2").css({ transition: 'all 1.8s' });
$("#item-3").css({ transition: 'all 1.6s' });
$("#item-4").css({ transition: 'all 1.4s' });
$("#item-5").css({ transition: 'all 1.2s' });
$(this).css({ transition: 'all 1s' });
});发布于 2019-09-10 17:48:28
正如用户Temani Afif指出的那样,我想要实现的是不可能使用flex。我已经切换到块显示和“硬编码”的每一个大小和位置。
Temani Afif对此作了评论(以及评论部分中的更多内容):
让元素慢慢收缩,让元素快速增长是没有意义的。所有元素的总宽度都需要保持不变,所以它们都需要有相同的时间。
https://stackoverflow.com/questions/57760480
复制相似问题