回流时的 CSS3 过渡
以这个dom为例。
<div id="container" style="transition: width 1s ease-in-out;">
<div style="width: 400px; display: none;"></div>
<div style="width: 200px;"></div>
</div>
如果我交替隐藏哪个内部 div,我可以触发 CSS3 转换(通过回流)吗?如果可能的话,我可以添加许多内部 div 并在它们之间平滑地交替,而不必知道它们的大小。
Take this dom as an example.
<div id="container" style="transition: width 1s ease-in-out;">
<div style="width: 400px; display: none;"></div>
<div style="width: 200px;"></div>
</div>
If I alternate which inner div is hidden, can I trigger the CSS3 transition (via reflow)? If this were possible, I could add many inner divs and alternate between them smoothly without having to know what size they were.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为单独通过 CSS 是可能的 - 过渡是不可继承的,因此它们必须应用于有问题的嵌套元素,并且无论如何都不能在没有宽度的情况下应用宽度过渡,因此例如嵌套的 div 需要它的
width
和0
设置为在悬停或 JS 单击或某些事件时在它们之间进行转换,但我认为我真的无法理解这个问题;
会将其应用于所有子 div 然后您只需切换显示和宽度,但是您仍然想这样做吗?
I wouldn't think it's possible via CSS alone - transitions are not inheritable, so they would have to be applied to the nested elements in question, and a width transition couldn't be applied without the width anyway so e.g. the nested div would need it's
width
and0
set to transition between them either on a hover or a JS click or some eventhowever I think I really am failing to understand the question;
would apply it to all child divs then you just toggle the display and width however you're thinking of doing it anyway?