我有两个div,我使用transition-group在它们之间转换,这是应该的-然而,div转换下面的内容,是“跳跃”取决于div的高度。我想要的是跳跃被阻止,而是它以某种方式动画化,所以当在元素之间切换时,我得到了一个很好的平滑过渡,而不是它“推”到内容与“跳跃”。
希望有道理:)
我在这里设置了一个关于codesandbox的示例:https://codesandbox.io/s/reverent-stallman-8ixhp?file=/src/components/HelloWorld.vue
模板如下所示:
<div class="hello">
<button @click="groupShowOne">Show first {{ gShowFirst }}</button>
<button @click="groupShowTwo">Show second {{ gShowSecond }}</button>
<transition-group name="fade-group" tag="div" mode="out-in" appear>
<div
class="group-element"
v-if="gShowFirst"
style="background-color: yellow"
>
<h3>This is a headline</h3>
<p>This is a text</p>
</div>
<div
class="group-element"
v-if="gShowSecond"
style="background-color: red"
>
<h3>
This is a headline <br />This is a headline <br />This is a headline
This is a headline This is a headline This is a headline
</h3>
<p>
This is a text This is a text This is a text This is a text This is a
text v This is a text v <br />This is a text This is a text This is a
text This is a text This is a text v This is a text v <br />This is a
text This is a text This is a text This is a text This is a text v
This is a text v
</p>
</div>
</transition-group>
<div style="background-color: blue; min-height: 500px; color: #FFF">
Prevent this div from jumping<br />
</div>
</div>
动画外观为:
<style scoped>
.group-element {
width: 100%;
min-height: 100px;
max-height: 20000px;
transition: all 0.5s;
}
.fade-group-enter,
.fade-group-leave-to {
opacity: 1;
}
.fade-group-leave-active {
opacity: 0;
position: absolute;
}
</style>
2条答案
按热度按时间aoyhnmkz1#
尝试this
1.设置被动div中的过渡属性:
1.让它做一些动画
部门:
bfnvny8b2#
您可以尝试:
*-move
类。但是,transition-group
必须应用于所有元素,包括具有v-move
类的元素,才能工作。(
*-move
基本上是将项目从其原始位置动画到其新位置,使其平滑,而不是跳跃)showSecond
或showFirst
等于某个值时,您仍然可以使用现有的内容,并为蓝框动态绑定一个单独的CSS过渡。