Is there any way to manually or programmatically trigger an enter or leave transition in vue.js?
From reading the documentation it seems that transitions only ever trigger for v-if and v-show.
However, my use-case is to animate the movement of an element from one position to another on one user event, and move it back on a second user event.
The animations themselves are easy to achieve using Velocity, but I am having issues triggering them when required.
I don't want to change the visibility or presence of the element, so switching v-show and v-if to start the transition is out of the question.
I have tried using a key on the element, but this is basically the same as creating and destroying it, causing both enter and leave transitions (move and move back) to fire sequentially.
Is there any way to manually trigger an enter transition, then subsequently trigger the leave transition, while preserving the visibility of the element itself?
For illustration here is a codepen with the move animations set up for enter and leave.
<div id="app">
<transition
name="move"
@enter="enter"
@leave="leave"
@after-enter="afterEnter"
@after-leave="afterLeave"
>
<div
id="moveMe"
@click="itemClick"
:key="itemKey">
</div>
</transition>
</div>
var app = new Vue({
el: "#app",
data: {
itemKey: 0
},
methods: {
itemClick() {
this.itemKey++
},
enter(el, done) {
Velocity(el, { left: '200px'}, {
duration: 500,
complete: function() {
done()
}
})
},
afterEnter(el) {
el.style.left = "200px"
},
leave(el, done) {
Velocity(el, { left: '0px'}, {
duration: 500,
complete: function() {
done()
}
})
},
afterLeave(el) {
el.style.left = "0px"
}
}
})
What I am trying to achieve is to trigger the enter (move right) animation on click of the element, and then trigger the leave (move left) animation on second click of the element.