Add delay between Vue router-view transitions - vuejs3

I'm trying to do some delay between route changes.
For example user clicks on router-link and after previous View faded out I want to show some kind of Priomise based loading animation before next View's fade in.
Here's my code:
<nav>
<router-link to="/">Home</router-link>
|
<router-link to="/about">About</router-link>
</nav>
<router-view v-slot="{ Component }">
<transition
mode="out-in"
name="custom-classes"
enter-active-class="fade-enter-active"
leave-active-class="fade-leave-active"
enter-from-class="fade-enter-from"
leave-to-class="fade-leave-to"
>
<component :is="Component" :key="$route.path"/>
</transition>
</router-view>
<style lang="less">
.fade-enter-active,
.fade-leave-active {
transition: opacity .5s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
</style>
I've tried some custom classes but don't know how to stop between transitions.

In case someone's looking for same problem I've ended up with the following code.
<nav>
<router-link to="/">Home</router-link>
|
<router-link to="/about">About</router-link>
</nav>
<router-view v-slot="{ Component }">
<transition
mode="out-in"
name="custom-classes"
enter-active-class="fade-enter-active"
leave-active-class="fade-leave-active"
enter-from-class="fade-enter-from"
leave-to-class="fade-leave-to"
>
<component :is="Component" :key="$route.path" v-if="component_visible"/>
</transition>
</router-view>
I've added v-if for the <component/> based on computed property
computed: {
component_visible() {
return this.$store.state.common.transition;
}
}
And then just change it's value in any place that needed.

Related

How to do an ease in transition after a react if statement

I'm trying to create a catalogue which has a filter component. Once the filter button is clicked, it triggers a variable to turn true which then switches what is being shown on the screen. I want to know how I can make this switch smooth and ease in using css. Here is my code:
<div>
{this.state.showProjects === true &&
<div className="test">
{this.state.projects && this.state.projects.map((project) => (
<ProjectDetails key={project._id} project={project}/>
))}
</div>
}
{this.state.showProjects === false &&
<div className="initial-screen">
Enter filter options to get started!
</div>
}
</div>
Where and how should I incorporate the css ease property?
If I'm understanding what your ask is, you can implement a class-based solution that has your transition effects in there.
<div>
<div className=`test content ${this.state.showProjects && 'active'}`>
{this.state.projects && this.state.projects.map((project) => (
<ProjectDetails key={project._id} project={project}/>
))}
</div>
<div className=`initial-screen content ${!this.state.showProjects && 'active'}`>
Enter filter options to get started!
</div>
</div>
I added another class called content which would have the main transition styling that you would need for your animations. The active class would be your identifier as to what is currently being displayed.
.content {
opacity: 0;
transition-duraction: 2s;
transition-timing-function: ease;
&.active {
opacity: 100;
}
}
This would just add a simple fade-in/fade-out, but you can use this at a simple template for you to use to start adding in more styling; like movement.

Stripe payment select styling

I'm trying to style the stripe dropdown select to match bootstrap's select. here is my html
<form id="payment-form">
<div class="form-row">
<div>
<label for="bank-element">
Bank
</label>
<div id="bank-element">
<!-- A Stripe Element will be inserted here. -->
</div>
</div>
</div>
<button id="button" data-secret="<?= $intent->client_secret ?>">
Submit Payment
</button>
<!-- Used to display form errors. -->
<div id="error-message" role="alert"></div>
</form>
in my js file i have this
var style = {
base: {
'padding': "10px 12px",
'color': '#495057',
'fontFamily': 'apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif',
'border-color': '#80BDFF',
'outline':'0',
'box-shadow': '0 0 0 .2rem rgba(0,123,255,.25)',
'transition': 'border-color .15s ease-in-out, box-shadow .15s ease-in-out'
},
invalid: {
color: "#fa755a"
}
};
var Bank = elements.create(
'Bank',
{style: style, accountHolderType: 'individual'}
);
id="bank-element" is there the dropdown select is. Anyone know how to do this? or that I'm missing. Thank you
Great question, but unfortunately you're limited to the style options listed here:
https://stripe.com/docs/js/appendix/style
This means that you won't be able to set: border-color, transition, border-color, or outline on the element itself. You can apply a border & animations to the container div, but you won't be able to set up the animation transition on anything inside the Element.

Vue transitioned element not showing after transition is complete

I'm trying to animate an element to full browser height when the user clicks on the top bar. The animation works, but once the (enter) animation is finished the container jumps back to zero height, while it's supposed to stay until the user clicks the close button.
How do I make the container stay 100vh when the animation is finished?
I tried adding height: 100vh; on the element, but by doing that the transition animation stopped working. (by removing the height, the animation works but the element disappears)
Not sure if it matters, but I changed v-if into v-show and also added a key on the container, but that didn't seem to make a difference.
Here's a link to my code. And to view the animation.
<!-- AboutMeComponent.vue -->
<template>
<div>
<div v-show="!extended" class="small-container" #click="extended = !extended">
<h4>
CLICK ME
</h4>
</div>
<ExtendTransition>
<div v-show="extended" key="1" class="main-container">
<div class="icon-container">
<a v-show="extended" href="#" #click="extended = !extended">
<font-awesome-icon icon="times"/>
</a>
</div>
</div>
</ExtendTransition>
</div>
</template>
<!-- ExtendTransition.vue -->
<template>
<transition appear name="extend" mode="out-in">
<slot></slot>
</transition>
</template>
<style lang="scss">
.extend-enter-active,
.extend-leave-active {
transition: 3s;
}
.extend-enter-to,
.extend-leave {
height: 100vh;
}
.extend-leave-to {
height: calc(20px + 1vw);
}
.extend-enter {
height: calc(40px + 3vw);
}
</style>
A transition only is applied while the transition is playing. Once the transition finished, all transition classes are removed. This means that your element must have the CSS you want it to have after the transition is finished. You can then use the transition classes to set the initial state and define the transition to get to that point, and from that point to the initial state.
The easiest way to solve this problem is by making ExtendTransition.vue the only component that worries about the transition, and using a wrapper that wraps the thing you want to extend.
<template>
<transition appear name="extend" mode="out-in">
<div class="extend-transition-wrapper" v-show="extended">
<slot></slot>
</div>
</transition>
</template>
<script>
export default {
props: {
extended: {
type: Boolean,
default: false
}
}
};
</script>
The only thing you then have to do is to set the default state of your wrapper:
.extend-transition-wrapper {
height: 100vh;
will-change: height;
position: relative;
}
In your ABoutMeComponent.vue you then use a prop to show and hide the content:
<ExtendTransition :extended="extended">
<div class="main-container">
<div class="icon-container">
<a v-show="extended" href="#" #click="extended = !extended">
<font-awesome-icon icon="times"/>
</a>
</div>
</div>
</ExtendTransition>
And finally you set .main-container to always have a height of 100%. Since we set the wrapper to have position: relative, this will force the main container to become the height of that element.

Vue2 : Make Page Fade In with "appear" transition and still use routing transition too

I was trying to do a page fade in when my app initially loads using appear; however, I am already using a routing css animation that does a fade in and fade out when going from page to page, but it still leaves me with an abrupt display of my page when it initially loads. So far, my attempts to add another transition tag around the routing transition in a outer nested way has failed. It still loads with an abrupt display of page. Any suggestions?
<template>
<div id="app">
<v-app>
<main>
<transition name="appearPageFadeIn" appear><!-- new appear tag -->
<cq-nav-mobile></cq-nav-mobile>
<cq-nav-desktop></cq-nav-desktop>
<transition name="interPageFadeOutIn" mode="out-in">
<router-view></router-view>
</transition>
<cq-footer></cq-footer>
</transition>
</main>
</v-app>
</div>
</template>
<!-- CSS -->
/* appear page animation */
.appearPageFadeIn-appear {
opacity: 0;
}
.appearPageFadeIn-appear-active {
transition: opacity 1s;
}
/* inter page routing animation */
.interPageFadeOutIn-enter {
opacity: 0;
}
.interPageFadeOutIn-enter-active {
transition: opacity 1s;
}
.interPageFadeOutIn-leave {
opacity: 1; //default
}
.interPageFadeOutIn-leave-active {
transition: opacity 1s;
opacity: 0;
}

How to use ng-animate to add slide effect on menu

I am trying to implement a slide effect using ng-animate and CSS styles, but can't figure out what's wrong with my code...
Can I do this using values in percentages for min-height and max-height? I cant use fixed values in px.
JSFIDDLE
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
Click to toggle menu
<div class="menu" ng-show="collapsed" ng-animate="{show: 'menu-show', hide: 'menu-hide'}">
<div class="files">
<input type="checkbox" />
<label>first</label>
<input type="checkbox" />
<label>second</label>
</div>
<div class="diffs">
<input type="checkbox" />
<label>first</label>
<input type="checkbox" />
<label>second</label>
</div>
</div>
</div>
CSS:
.menu-show-setup, .menu-hide-setup {
transition:all 0.5s ease-out;
overflow:hidden
}
.menu-show-setup {
max-height:0;
}
.menu-show-setup.menu-show-start {
max-height:25%;
}
.menu-hide-setup {
max-height:25%;
}
.menu-hide-setup.menu-hide-start {
max-height:0;
}
First ensure you have angular and angular-animate loaded.
The CDN for angular-animate is ...
<script src="//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js"></script>
Then you need to reference the animations that ngAnimate gives ...
https://docs.angularjs.org/api/ngAnimate
For example, ng-if when switched from false to true will add the class .fade AND .ng-enter to the element on which the ng-if is located. These classes will be automatically removed after a short time. ngAnimate does this for you.
What you HAVE to do is to style what these classes do ...
example:
.fade.ng-enter {
transition:0.5s linear all;
opacity:0;
}
/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active {
opacity:1;
}
now ng-animate will animate from .fade.ng-enter to .fade.ng-enter.ng-enter-active
if you do not define these styles ng-animate will do nothing.
You will see classes being added and remove by ng-animate if you inspect the relevant element in your browser's develop tools. If you cannot see these classes being added and removed then something is wrong with your loading of angular or ng-animate.

Resources