gpt4 book ai didi

javascript - 使用显示 : flex; 为菜单设置动画

转载 作者:太空宇宙 更新时间:2023-11-03 21:21:33 24 4
gpt4 key购买 nike

我想使用 display:flex 和 JavaScript(jQuery 或 vanilla)来制作菜单动画。这不起作用:

$('#blah').click(function(e){
e.preventDefault();
$('#mid').animate({flex:'0 0 20%'});
return false;
});
* { margin:0; padding: 0; }
#menu { background-color: yellow; display: flex; }
#left {background-color: green; flex: 0 0 200px; }
#mid { background-color: red; flex: 0 0 40%; }
#right {background-color: blue; flex: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="menu">
<div id="left">left green: 200px</div>
<div id="mid">mid red: 40% of browser width</div>
<div id="right">right blue: rest</div>
</div>
<div>
<a href="" id="blah">click here to animate mid to 20%!</a>
</div>

使用 CSS display: flex 为菜单设置动画 ?

最佳答案

animate 函数中使用 flexBasis 而不是 flex

$('#blah').click(function(e){
e.preventDefault();
$('#mid').animate({flexBasis:'20%'});
return false;
});
* { margin:0; padding: 0; }
#menu { background-color: yellow; display: flex; }
#left {background-color: green; flex: 0 0 200px; }
#mid { background-color: red; flex: 0 0 40%; }
#right {background-color: blue; flex: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="menu">
<div id="left">left green: 200px</div>
<div id="mid">mid red: 40% of browser width</div>
<div id="right">right blue: rest</div>
</div>
<div>
<a href="" id="blah">click here to animate mid to 20%!</a>
</div>

关于javascript - 使用显示 : flex; 为菜单设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36851293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com