How to reverse transiton in Vue 2 - css

I am trying to create a bottomsheet in vue2. Although the same could be achieved in pure css but I chose to work Vue way.
Below is my working example
I am successfully able to animate on enter but it fails on leave.
What am I missing here ?
<template>
<transition name="bottomsheet">
<div class="bottomsheet" v-if="show">
<transition name="bottomsheet-glass" appear>
<div class="glass" #click="$emit('update:show', false)"></div>
</transition>
<transition name="bottomsheet-container" appear>
<div class="bottomsheet-container">
<div class="bottomsheet-toolbar text-right">
<button #click="$emit('update:show', false)">Close</button>
</div>
<div class="bottomsheet-body">
<slot />
</div>
</div>
</transition>
</div>
</transition>
</template>
<script>
export default {
props: ["show"],
};
</script>
<style lang="scss" scoped>
.bottomsheet {
.glass {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
}
&-container {
bottom: 0;
left: 0;
right: 0;
position: fixed;
width: 100%;
color: black;
}
&-body {
padding: 20px 20px;
overflow: auto;
background: white;
height: calc(100vh - 250px);
}
}
.bottomsheet-glass-enter-active {
animation: fade-in 2s;
}
.bottomsheet-glass-leave-active {
animation: fade-in 2s reverse;
}
.bottomsheet-container-enter-active {
animation: wait-and-slide-up 4s;
}
.bottomsheet-container-leave-active {
animation: wait-and-slide-up 4s reverse;
}
#keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes wait-and-slide-up {
0% {
transform: translateY(100%);
}
50% {
transform: translateY(100%);
}
100% {
transform: translateY(0);
}
}
</style>

Related

CSS animation, some animations finish, then repeat them in order

as a newbie in CSS animations i'm trying to make some spinners,
Unfortunately i am not able to make repeat a cycle of animations and i'm searching help!
Here is the code:
.rotate {
transform: rotate(-45deg);
display: flex;
}
#column {
display: flex;
flex-direction: column;
}
.block3 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: 0s;
}
.block4 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: .4s;
}
.block2 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: .8s;
}
.block1 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: 1.2s;
}
#keyframes fade {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="it">
<head>
<style>
body {
position: absolute;
margin: 0;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.margin {
margin-top: 200px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
</style>
</head>
<body>
<section class="animation rotate">
<div id="column">
<div class="block1"></div>
<div class="block2"></div>
</div>
<div id="column">
<div class="block3"></div>
<div class="block4"></div>
</div>
</section>
</body>
</html>
I even tried with infinite attribute but obviously it continues to repeat every block:
.rotate {
transform: rotate(-45deg);
display: flex;
}
#column {
display: flex;
flex-direction: column;
}
.block3 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: 0s;
}
.block4 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: .4s;
}
.block2 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: .8s;
}
.block1 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: 1.2s;
}
#keyframes fade {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="it">
<head>
<style>
body {
position: absolute;
margin: 0;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.margin {
margin-top: 200px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
</style>
</head>
<body>
<section class="animation rotate">
<div id="column">
<div class="block1"></div>
<div class="block2"></div>
</div>
<div id="column">
<div class="block3"></div>
<div class="block4"></div>
</div>
</section>
</body>
</html>
So in conclusion:
block1 executes, block2 executes, block3 executes, block4 executes then repeat from block1
You will need to create a keyframe for each block:
.rotate {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg) ;
display: flex;
flex-wrap: wrap;
width: 100px; /* change this to control the size */
}
.rotate div {
flex:1 1 48%; /* little less than 50% to consider the margin */
margin: 1px;
background-color: black;
animation: 2s linear infinite;
}
/* maintain square ratio*/
.rotate div::before {
content: "";
display: block;
padding-top: 100%;
}
/**/
.rotate div:nth-child(1) { animation-name:fade4}
.rotate div:nth-child(2) { animation-name:fade1}
.rotate div:nth-child(3) { animation-name:fade3}
.rotate div:nth-child(4) { animation-name:fade2}
/* [0% first one 20%][20% second one 40%][40% third one 60%][60% fourth one 80%][80% pause 100%] */
#keyframes fade1 {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
20%,100% {
opacity: 0;
}
}
#keyframes fade2 {
0%,20% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
40%,100% {
opacity: 0;
}
}
#keyframes fade3 {
0%,40% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
60%,100% {
opacity: 0;
}
}
#keyframes fade4 {
0%,60% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
80%,100% {
opacity: 0;
}
}
<section class="animation rotate">
<div></div>
<div></div>
<div></div>
<div></div>
</section>

How can I show loader in the center with overlay light grey background in every (button, section, body) case

Grey background should be cover full width and height of parent.
<body>
<div class="loader"></div>
</body>
<button>
<div class="loader"></div>
</button>
<section>
<div class="loader"></div>
</section>
.button-wrap {
width: 200px;
height: 100px;
position: relative;
}
.spinner-wrapper {
background: lightgrey;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
display: grid;
place-items: center;
}
.spinner {
border: 5px solid #f3f3f3;
border-radius: 50%;
border-top: 5px solid #3498db;
width: 50px;
height: 50px;
-webkit-animation: spin 2s linear infinite;
/* Safari */
animation: spin 2s linear infinite;
}
/* Safari */
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
<button class="button-wrap">
submit
<div class="inner">
<div class="loader"></div>
</div>
</button>
<div class="spinner-wrapper">
<div class="spinner"></div>
</div>

Unable to animate with transform functions

I've been trying to animate my image with almost all transform functions without success.
After googling it appeared that setting with: auto might be the cause.
But removing it from my style doesn't change anything at all. Still no animation.
Here you have my code :
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
transition: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
#keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="../images/Green-Monster-8-icon-128.png" class="logo" />
</div>
</body>
What is wrong in my code ?
Thanks in advance.
You have to use animation instead of transition
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
animation: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
#keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="https://via.placeholder.com/50" class="logo" />
</div>
</body>

Is it possible to alternate z-index on CSS animation

I have been trying this multiple ways with no success. JavaScript, TweenLite, etc. I need to alternate two <div> tags, slide1 & slide2, that live inside slide. Fading one out to fading one in. A continuous loop. I can use a basic css #keyframes animation like bellow. It works fine, but they are clickable links and one <div> will always remain on top.
Is there a way to loop the z-index of each div in the #keyframes anim?
Or maybe a completely better method?
CSS
.slider {
max-width: 300px;
height: 200px;
margin: 20px auto;
position: relative;
}
.slide1,.slide2 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
animation:fade 8s infinite;
-webkit-animation:fade 8s infinite;
}
.slide2 {
animation:fade2 8s infinite;
-webkit-animation:fade2 8s infinite;
}
#keyframes fade
{
0% {opacity:1}
33.333% { opacity: 0}
66.666% { opacity: 0}
100% { opacity: 1}
}
#keyframes fade2
{
0% {opacity:0}
33.333% { opacity: 1}
66.666% { opacity: 0 }
100% { opacity: 0}
}
HTML
<div class="slider">
<div class="slide1"></div>
<div class="slide2"></div>
</div>
They seem to be working for me, check it out: https://codepen.io/giovannipds/pen/LzgYaa
<style>
.slider {
line-height: 1.5;
height: 200px;
margin: 20px auto;
position: relative;
width: 300px;
}
.slide {
padding: 20px;
position: absolute;
width: 100%;
height: 100%;
}
.slide,
.slide a {
color: #fff;
}
.slide1 {
animation: fade 8s infinite;
background: red;
}
.slide2 {
animation: fade2 8s infinite;
background: blue;
}
#keyframes fade
{
0% { opacity: 1 ; z-index: 2; }
33.333% { opacity: 0; z-index: 1; }
66.666% { opacity: 0; z-index: 1; }
100% { opacity: 1; z-index: 2; }
}
#keyframes fade2
{
0% { opacity: 0; z-index: 1; }
33.333% { opacity: 1; z-index: 2; }
66.666% { opacity: 1; z-index: 2; }
100% { opacity: 0; z-index: 1; }
}
</style>
<div class="slider">
<div class="slide slide1">
<ul>
<li>Google</li>
<li>Globo.com</li>
</ul>
</div>
<div class="slide slide2">
<ul>
<li>Love Mondays</li>
<li>Hotmail</li>
</ul>
</div>
</div>

CSS Transition on a css transform property causing the parent to flicker only in Google Chrome

I have a pretty specific rendering issue I came across. When doing a css transition on a transform property, the direct parent is dimming during the transition, even though the opacity is not being changed. This only happens in Chrome, not Safari or Firefox, and I'm on a mac.
Has anyone seen this issue or have any thoughts?
$('#toggle').click(function(e){
$('#bar').toggleClass('on');
});
body {
background: #222;
}
#bar {
background: #999;
opacity: .5;
height: 4px;
border-radius: 2px;
width: 300px;
margin: 30px 5px;
}
#inner {
background: #ee2f51;
height: 4px;
border-radius: 2px;
width: 1px;
transition: all 1s;
transform-origin: left;
transform: scaleX(100);
}
.on #inner{
transform: scaleX(300);
}
/*
//option pulse animation
#bar.on {
animation: pulse 1s ease-in-out;
}
#keyframes pulse {
0% {
opacity: .5;
}
50% {
opacity: 1;
}
100% {
opacity: .5;
}
} */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
<div id="bar">
<div id="inner"></div>
</div>
</div>
<button id="toggle">
toggle bar
</button>
If you remove opacity: 0.5 from #bar the problem goes away, but your colors are different. This version works fine on all browsers, but you'll have to tweak the rgba to your liking.
$('#toggle').click(function(e){
$('#bar').toggleClass('on');
});
body {
background: #222;
}
#bar {
background: rgba(153, 153, 153,0.65);
height: 4px;
border-radius: 2px;
width: 300px;
margin: 30px 5px;
}
#inner {
background: rgba(193, 16, 47, 0.65);
height: 4px;
border-radius: 2px;
width: 1px;
transition: all 1s;
transform-origin: left;
transform: scaleX(100);
}
.on #inner {
transform: scaleX(300);
}
/*
//option pulse animation
#bar.on {
animation: pulse 1s ease-in-out;
}
#keyframes pulse {
0% {
opacity: .5;
}
50% {
opacity: 1;
}
100% {
opacity: .5;
}
} */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
<div id="bar">
<div id="inner"></div>
</div>
</div>
<button id="toggle">
toggle bar
</button>

Resources