gpt4 book ai didi

css - 使用 angular-ui 从/到视口(viewport)的右边缘展开/折叠 div

转载 作者:行者123 更新时间:2023-11-28 17:39:00 27 4
gpt4 key购买 nike

我正在创建一个“抽屉”div,它会随着浏览器窗口右侧的过渡而出现和消失。我正在使用 Angular-UI-Bootstrap 的 collapse directive ,使用 this question 的答案中提供的代码进行了修改.我的过渡工作正常,当抽屉折叠时它看起来不错,但当 div 展开到 View 中时,它的过渡很奇怪。

enter image description here

引用上图,右侧的蓝色区域(抽屉 div)以越来越慢的速度扩展,几乎在到达“Some Link”的末尾时停止 <li><a>内容,然后再次加速到正常速度。这种怪异现象只发生在展开时,不会发生在折叠时。在 this plunk 中查看代码和奇怪的行为.

HTML:

<body ng-app="app" ng-controller="theController">
<div id="main" class="col-md-12">
<div id="drawer" collapse-width="drawerIsCollapsed" expand-width="200">
<ul>
<li><a href="#">Some link</a></li>
<li><a href="#">Some link</a></li>
<li><a href="#">Some link</a></li>
<li><a href="#">Some link</a></li>
</ul>
</div>
<div id="content" class="col-md-12">
<button type="button" ng-click="drawerIsCollapsed = !drawerIsCollapsed">Toggle</button>
<h1>This is the main content and it is going to be really wide so i can tell if the text will wrap when i toggle the right drawer or if it will do what it should and continue under the drawer.</h1>
</div>
</div>
<script src="divSandvoxController.js"></script>
</body>

CSS:

body{
height: 100%;
width: 100%;
background-color: #efefef;
}
#main{
height: 768px;
width: 100%;
background-color: aliceblue;
}
#content{
height: 768px;
width: 100%;
background-color: orange;
position: relative;
}
#drawer{
height: 768px;
width: 200px;
background-color: lightsteelblue;
position: absolute;
right: 0;
top: 0;
z-index: 99;
white-space: nowrap;
}
.collapsing-width{
position: relative;
overflow-x: hidden;
-webkit-transition: width 0.35s ease;
-moz-transition: width 0.35s ease;
-o-transition: width 0.35s ease;
transition: width 0.35s ease;
}
.collapse{
overflow-x: hidden;
}

修改后的 angular 指令的 javascript 可在上面链接的问题的已接受答案中找到,但如果需要,我会在此处发布。

有谁知道为什么会发生这种情况以及如何解决它以便展开过渡平滑,就像折叠一样?

最佳答案

发生这种情况是因为 element[0].scrollWidth 并不代表最终展开大小 - 它会展开到 102px 的值,然后突然弹出以最终确定为完整大小(200px - #drawer 的宽度)。

你可以把这个size传给expand()中的doTransition调用,就很顺利了:

doTransition({ width: '200px' })...

关于css - 使用 angular-ui 从/到视口(viewport)的右边缘展开/折叠 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24541686/

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