【问题标题】:Transitioning multiple child elements with one <transition> wrapper使用一个 <transition> 包装器转换多个子元素
【发布时间】:2018-09-25 09:56:39
【问题描述】:

我想在一个父 v-if 状态更改中设置多个转换(在单独的子元素上)。

例如,当我显示模态框时,我希望背景模糊为fadeIn(使用不透明度),模态内容为slideIn(使用过渡或动画)。我目前的情况如下,当我使用过渡时,背景模糊元素 (.modal) 与内容 (.modal__content) 一起过渡:

<transition enter-active-class="animated slideInRight" leave-active-class="animated slideOutRight">
  <div class="modal" v-if="isVisible">
    <div class="modal__content">
      </slot><slot/>
    </div>
  </div>
</transition>

【问题讨论】:

  • korun,您可以发布您的解决方案作为答案吗?
  • 当时没有发现任何有用的东西,最好的方法是采用更多基于 JS 的方法,如下面的答案所述。我在过去的一年里使用 React,所以我可能已经过时了 :)

标签: vue.js vuejs-transition


【解决方案1】:

您可以在.modal 淡入后使用JS hook 来触发幻灯片动画:

<template>
  <transition name="fade" @after-enter="showContent = true">
    <div class="modal" v-if="isVisible">
      <transition name="slide">
        <div class="modal__content" v-if="showContent">
        </div>
      </transition>
    </div>
  </transition>
</template>

<script>
export default {
    data() {
        return {
            isVisible: false,
            showContent: false
        };
    }
};
</script>

【讨论】:

  • 对不起,我迟到了。虽然解决方案很有趣,但我一直在寻找元素的并行转换,我设法使用转换元素的 appear 属性来实现。这种类型的解决方案还有两个注意事项 - 代码很冗长并且没有离开动画。
  • @korun,如果您找到了满意的解决方案,请post it as an answer,这样其他人也可以从中受益:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多