首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在增长/收缩时,是否可能对flex容器中的每个flex元素有不同的转换时间?

在增长/收缩时,是否可能对flex容器中的每个flex元素有不同的转换时间?
EN

Stack Overflow用户
提问于 2019-09-02 16:54:16
回答 1查看 65关注 0票数 2

我有一组不断增长/收缩的flex项目:悬停我的问题是,即使我指定每一个都有自己的转换时间,它们都需要相同的时间来完成它们的动画。

是否可以修复这个问题,或者我必须使用"display: block“并手动编码每个元素的大小?

代码语言:javascript
运行
复制
<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>
代码语言:javascript
运行
复制
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;
}
代码语言:javascript
运行
复制
// 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' });
});

这是笔https://codepen.io/mateus-ramos/pen/RwbZKgy

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-10 17:48:28

正如用户Temani Afif指出的那样,我想要实现的是不可能使用flex。我已经切换到块显示和“硬编码”的每一个大小和位置。

Temani Afif对此作了评论(以及评论部分中的更多内容):

让元素慢慢收缩,让元素快速增长是没有意义的。所有元素的总宽度都需要保持不变,所以它们都需要有相同的时间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57760480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档