gpt4 book ai didi

css - 如何修复CSS中的动画故障?

转载 作者:行者123 更新时间:2023-11-28 00:13:08 26 4
gpt4 key购买 nike

我正在尝试创建一个简单的侧边菜单,其中包含与其宽度变化相匹配的动画。当菜单关闭时,我只想显示图标,当它打开时,我想同时显示 - 图标和文本。动画效果很好,但切换时会出现某种故障……当文本出现时,它似乎与图标断线了。菜单打开时,如何相应地延迟文本显示?

Fiddle

HTML

     <div ng-app class="container" ng-controller="MyCtrl">
<div class="row">
<div class="col-md-3"><button class="btn btn-success" ng-click="toggleSideMenu()">
<i class="fa fa-bars"></i></button>
<div class="side-menu-wrapper" ng-class="{'menu-open':!!isMenuExpanded, 'menu-closed':!isMenuExpanded}">
<ul class="list-group">
<li class="list-item">
<i class="fa fa-cog">
</i><span>
First item</span></li>
<li class="list-item">
<i class="fa fa-book"></i>
<span>
First item</span></li>
<li class="list-item">
<i class="fa fa-pencil"></i>
<span>
First item</span></li>
</ul>
</div>
</div>
<div class="col-md-9">

</div>
</div>
</div>

CSS

    .container {
margin-top: 15px;
}

.side-menu-wrapper {
background-color: rgb(41, 44, 90);
height: 100vh;
transition: width 0.5s ease-in;
}

.side-menu-wrapper span {
margin-left: 5px;
}

.side-menu-wrapper.menu-closed {
width: 15%;
}

.side-menu-wrapper.menu-closed span {
/* display: none;
opacity: 0; */
transition: opacity 1s ease-out;
opacity: 0;
height: 0;
overflow: hidden;
}

.side-menu-wrapper.menu-open span {
display: inline-block;
float: right;
opacity: 1;
}

.side-menu-wrapper.menu-open {
opacity: 1;
transition: width 0.5s ease-out;
width: 100%;
}

.list-item {
background-color: transparent;
color: rgb(161, 165, 224);
position: relative;
display: flex;
padding: 10px 15px;
border-bottom: 1px solid rgb(161, 165, 224);
}

Angular

  function MyCtrl($scope) {
$scope.isMenuExpanded = false;
$scope.toggleSideMenu = function() {
$scope.isMenuExpanded = !$scope.isMenuExpanded;
}
}

最佳答案

问题是在.side-menu-wrapper.menu-closed span中设置height: 0;引起的

改变

    .side-menu-wrapper.menu-closed span {
/* display: none;
opacity: 0; */
transition: opacity 1s ease-out;
opacity: 0;
height: 0;
overflow: hidden;
}

   .side-menu-wrapper.menu-closed span {
/* display: none;
opacity: 0; */
transition: opacity 1s ease-out;
opacity: 0;
overflow: hidden;
}

   .side-menu-wrapper span {
margin-left: 5px;
}

   .side-menu-wrapper span {
margin-left: 5px;
opacity: 0;
white-space: nowrap;
}

关于css - 如何修复CSS中的动画故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55270807/

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