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>
vue.js
add a comment |
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>
vue.js
add a comment |
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>
vue.js
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
vue.js
edited Nov 10 at 18:39
Boussadjra Brahim
3,4702627
3,4702627
asked Nov 10 at 18:10
veoveo
132
132
add a comment |
add a comment |
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.
2
good explanation, +1 and congratulations 1k reputations
– Boussadjra Brahim
Nov 10 at 20:06
add a comment |
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.
2
good explanation, +1 and congratulations 1k reputations
– Boussadjra Brahim
Nov 10 at 20:06
add a comment |
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.
2
good explanation, +1 and congratulations 1k reputations
– Boussadjra Brahim
Nov 10 at 20:06
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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