Vue Transition inside the div element doesn't work











up vote
2
down vote

favorite












Could someone explain me, why the following code doesn't work?



<template>
<div class="modal">
<transition name="slide-in">
<div @click.stop class="modal__container">
<div @click="close" class="modal__button">
<span class="modal__button--close">Close</span>
</div>
</div>
</transition>
<transition name="fade-in">
<div @click="close" class="modal__overlay"/>
</transition>
</div>
</template>


I'm trying to create modal with two different animations (slide-in for text area and fade-in for modal overlay).



If i delete the element with class modal and edit code to the following everything works fine.



<template>
<transition name="slide-in">
<div @click.stop class="modal__container">
<div @click="close" class="modal__button">
<span class="modal__button--close">Close</span>
</div>
</div>
</transition>
</template>









share|improve this question




























    up vote
    2
    down vote

    favorite












    Could someone explain me, why the following code doesn't work?



    <template>
    <div class="modal">
    <transition name="slide-in">
    <div @click.stop class="modal__container">
    <div @click="close" class="modal__button">
    <span class="modal__button--close">Close</span>
    </div>
    </div>
    </transition>
    <transition name="fade-in">
    <div @click="close" class="modal__overlay"/>
    </transition>
    </div>
    </template>


    I'm trying to create modal with two different animations (slide-in for text area and fade-in for modal overlay).



    If i delete the element with class modal and edit code to the following everything works fine.



    <template>
    <transition name="slide-in">
    <div @click.stop class="modal__container">
    <div @click="close" class="modal__button">
    <span class="modal__button--close">Close</span>
    </div>
    </div>
    </transition>
    </template>









    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Could someone explain me, why the following code doesn't work?



      <template>
      <div class="modal">
      <transition name="slide-in">
      <div @click.stop class="modal__container">
      <div @click="close" class="modal__button">
      <span class="modal__button--close">Close</span>
      </div>
      </div>
      </transition>
      <transition name="fade-in">
      <div @click="close" class="modal__overlay"/>
      </transition>
      </div>
      </template>


      I'm trying to create modal with two different animations (slide-in for text area and fade-in for modal overlay).



      If i delete the element with class modal and edit code to the following everything works fine.



      <template>
      <transition name="slide-in">
      <div @click.stop class="modal__container">
      <div @click="close" class="modal__button">
      <span class="modal__button--close">Close</span>
      </div>
      </div>
      </transition>
      </template>









      share|improve this question















      Could someone explain me, why the following code doesn't work?



      <template>
      <div class="modal">
      <transition name="slide-in">
      <div @click.stop class="modal__container">
      <div @click="close" class="modal__button">
      <span class="modal__button--close">Close</span>
      </div>
      </div>
      </transition>
      <transition name="fade-in">
      <div @click="close" class="modal__overlay"/>
      </transition>
      </div>
      </template>


      I'm trying to create modal with two different animations (slide-in for text area and fade-in for modal overlay).



      If i delete the element with class modal and edit code to the following everything works fine.



      <template>
      <transition name="slide-in">
      <div @click.stop class="modal__container">
      <div @click="close" class="modal__button">
      <span class="modal__button--close">Close</span>
      </div>
      </div>
      </transition>
      </template>






      vue.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 18:39









      Boussadjra Brahim

      3,4702627




      3,4702627










      asked Nov 10 at 18:10









      veoveo

      132




      132
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Referencing Vue.js documentation on transitions




          Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM




          That means that DOM nodes that transition applies classes to, should be those which are inserted/updated/removed.



          Since it is a modal window, I assume that it has v-if directive applied in parent component to handle it's visibility. In order for transition to work, it should wrap DOM element that will be updated.



          You can understand it more easily if you move code of your modal window into the parent component. Just for better visualization of elements tree and transition's behavior.



          In first example, conditional rendering (v-if) applies to <div class="modal">, which is not wrapped with transition - therefore no animation will be triggered. At the same time, nested nodes are wrapped with transition, but there is nothing that will update or remove them. They are statically displayed and inserted initially on component's creation. Nothing to animate.



          In order for for it to work as expected following structure would be advisable:



          <template> 
          <transition name="fade-in">
          <div
          class="modal__overlay"
          @click="close"
          >
          <transition name="slide-in">
          <div
          v-if="containerVisible"
          class="modal__container"
          @click.stop
          >
          <div @click="close" class="modal__button">
          <span class="modal__button--close">Close</span>
          </div>
          </div>
          </transition>
          </div>
          </transition>
          </template>


          This solution expects modal__overlay to have position: fixed; style and variable containerVisible to be set to true inside mounted hook of modal component.






          share|improve this answer



















          • 2




            good explanation, +1 and congratulations 1k reputations
            – Boussadjra Brahim
            Nov 10 at 20:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241956%2fvue-transition-inside-the-div-element-doesnt-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          Referencing Vue.js documentation on transitions




          Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM




          That means that DOM nodes that transition applies classes to, should be those which are inserted/updated/removed.



          Since it is a modal window, I assume that it has v-if directive applied in parent component to handle it's visibility. In order for transition to work, it should wrap DOM element that will be updated.



          You can understand it more easily if you move code of your modal window into the parent component. Just for better visualization of elements tree and transition's behavior.



          In first example, conditional rendering (v-if) applies to <div class="modal">, which is not wrapped with transition - therefore no animation will be triggered. At the same time, nested nodes are wrapped with transition, but there is nothing that will update or remove them. They are statically displayed and inserted initially on component's creation. Nothing to animate.



          In order for for it to work as expected following structure would be advisable:



          <template> 
          <transition name="fade-in">
          <div
          class="modal__overlay"
          @click="close"
          >
          <transition name="slide-in">
          <div
          v-if="containerVisible"
          class="modal__container"
          @click.stop
          >
          <div @click="close" class="modal__button">
          <span class="modal__button--close">Close</span>
          </div>
          </div>
          </transition>
          </div>
          </transition>
          </template>


          This solution expects modal__overlay to have position: fixed; style and variable containerVisible to be set to true inside mounted hook of modal component.






          share|improve this answer



















          • 2




            good explanation, +1 and congratulations 1k reputations
            – Boussadjra Brahim
            Nov 10 at 20:06















          up vote
          2
          down vote



          accepted










          Referencing Vue.js documentation on transitions




          Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM




          That means that DOM nodes that transition applies classes to, should be those which are inserted/updated/removed.



          Since it is a modal window, I assume that it has v-if directive applied in parent component to handle it's visibility. In order for transition to work, it should wrap DOM element that will be updated.



          You can understand it more easily if you move code of your modal window into the parent component. Just for better visualization of elements tree and transition's behavior.



          In first example, conditional rendering (v-if) applies to <div class="modal">, which is not wrapped with transition - therefore no animation will be triggered. At the same time, nested nodes are wrapped with transition, but there is nothing that will update or remove them. They are statically displayed and inserted initially on component's creation. Nothing to animate.



          In order for for it to work as expected following structure would be advisable:



          <template> 
          <transition name="fade-in">
          <div
          class="modal__overlay"
          @click="close"
          >
          <transition name="slide-in">
          <div
          v-if="containerVisible"
          class="modal__container"
          @click.stop
          >
          <div @click="close" class="modal__button">
          <span class="modal__button--close">Close</span>
          </div>
          </div>
          </transition>
          </div>
          </transition>
          </template>


          This solution expects modal__overlay to have position: fixed; style and variable containerVisible to be set to true inside mounted hook of modal component.






          share|improve this answer



















          • 2




            good explanation, +1 and congratulations 1k reputations
            – Boussadjra Brahim
            Nov 10 at 20:06













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Referencing Vue.js documentation on transitions




          Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM




          That means that DOM nodes that transition applies classes to, should be those which are inserted/updated/removed.



          Since it is a modal window, I assume that it has v-if directive applied in parent component to handle it's visibility. In order for transition to work, it should wrap DOM element that will be updated.



          You can understand it more easily if you move code of your modal window into the parent component. Just for better visualization of elements tree and transition's behavior.



          In first example, conditional rendering (v-if) applies to <div class="modal">, which is not wrapped with transition - therefore no animation will be triggered. At the same time, nested nodes are wrapped with transition, but there is nothing that will update or remove them. They are statically displayed and inserted initially on component's creation. Nothing to animate.



          In order for for it to work as expected following structure would be advisable:



          <template> 
          <transition name="fade-in">
          <div
          class="modal__overlay"
          @click="close"
          >
          <transition name="slide-in">
          <div
          v-if="containerVisible"
          class="modal__container"
          @click.stop
          >
          <div @click="close" class="modal__button">
          <span class="modal__button--close">Close</span>
          </div>
          </div>
          </transition>
          </div>
          </transition>
          </template>


          This solution expects modal__overlay to have position: fixed; style and variable containerVisible to be set to true inside mounted hook of modal component.






          share|improve this answer














          Referencing Vue.js documentation on transitions




          Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM




          That means that DOM nodes that transition applies classes to, should be those which are inserted/updated/removed.



          Since it is a modal window, I assume that it has v-if directive applied in parent component to handle it's visibility. In order for transition to work, it should wrap DOM element that will be updated.



          You can understand it more easily if you move code of your modal window into the parent component. Just for better visualization of elements tree and transition's behavior.



          In first example, conditional rendering (v-if) applies to <div class="modal">, which is not wrapped with transition - therefore no animation will be triggered. At the same time, nested nodes are wrapped with transition, but there is nothing that will update or remove them. They are statically displayed and inserted initially on component's creation. Nothing to animate.



          In order for for it to work as expected following structure would be advisable:



          <template> 
          <transition name="fade-in">
          <div
          class="modal__overlay"
          @click="close"
          >
          <transition name="slide-in">
          <div
          v-if="containerVisible"
          class="modal__container"
          @click.stop
          >
          <div @click="close" class="modal__button">
          <span class="modal__button--close">Close</span>
          </div>
          </div>
          </transition>
          </div>
          </transition>
          </template>


          This solution expects modal__overlay to have position: fixed; style and variable containerVisible to be set to true inside mounted hook of modal component.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 20:08

























          answered Nov 10 at 19:50









          aBiscuit

          1,2421513




          1,2421513








          • 2




            good explanation, +1 and congratulations 1k reputations
            – Boussadjra Brahim
            Nov 10 at 20:06














          • 2




            good explanation, +1 and congratulations 1k reputations
            – Boussadjra Brahim
            Nov 10 at 20:06








          2




          2




          good explanation, +1 and congratulations 1k reputations
          – Boussadjra Brahim
          Nov 10 at 20:06




          good explanation, +1 and congratulations 1k reputations
          – Boussadjra Brahim
          Nov 10 at 20:06


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241956%2fvue-transition-inside-the-div-element-doesnt-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ