set an element initially hidden and stay visible after finishing animation - css-animations

in the example below:
wrap should be initially hidden
after one second - in should be outside of page
next second - it should go into page
finishing animation - it should stay visible - and here is the problem - it goes hidden
If I remove visibility:hidden at start - it is visible the first second - that's not allowed
how to do this ?
.wrap{
visibility:hidden; width:54px; height:54px; background:orange;
}
.wrap{animation: wrap 1s; animation-delay:1s}
#keyframes wrap{
0% {transform: translateX(-300px); visibility:visible}
100% {transform: translateX(0);}
}
<div class='wrap'></div>

This is happens, when the animation finished, the swap class gets its initial value from itself. To solve this you need add in the last keyframe (100%) visibility: visible; and also add animation-fill-mode: forwards; to stop the animation on the last keyframe.
.wrap {
visibility: hidden;
width: 54px;
height: 54px;
background: orange;
}
.wrap {
animation: wrap 1s;
animation-delay: 1s;
animation-fill-mode: forwards; /* new line */
}
#keyframes wrap {
0% {
transform: translateX(-300px);
visibility: visible;
}
100% {
transform: translateX(0);
visibility: visible; /* new line */
}
}
.wrap {
visibility: hidden;
width: 54px;
height: 54px;
background: orange;
}
.wrap {
animation: wrap 1s;
animation-delay: 1s;
animation-fill-mode: forwards; /* new line */
}
#keyframes wrap {
0% {
transform: translateX(-300px);
visibility: visible;
}
100% {
transform: translateX(0);
visibility: visible; /* new line */
}
}
<div class="wrap"></div>

Related

why my 3D animation runs smoothly on desktop but not on mobile?

it runs great on desktop but so janky on mobile :( sorry can't show you the result bcs I can't get permission TT_TT basically the animation is about having objects in 3D context of one perspective flying through z-index to your direction (and gets blurry when nearer)
I suspect it might have something to do with moving thousands of pixels? :(
How can I improve performance for mobile? Thanks!
HTML:
`
<template>
<div :class="{'js-loading': !hasLoaded}">
<img class="circle-bg" src="../assets/scene2-coins/circle-big-bg.svg" alt="circle-bg" #load="onImgLoad">
<img class="circle-bg--2" src="../assets/scene2-coins/circle-big-bg.svg" alt="circle-bg--2" #load="onImgLoad">
<img class="coin-silver" src="../assets/scene2-coins/coin-silver.svg" alt="coin-silver" #load="onImgLoad">
<img class="stars" src="../assets/scene2-coins/stars.svg" alt="stars" #load="onImgLoad">
<img class="confetti" src="../assets/scene2-coins/confetti.svg" alt="confetti" #load="onImgLoad">
<img class="confetti--2" src="../assets/scene2-coins/confetti.svg" alt="confetti--2" #load="onImgLoad">
<img class="coin-platinum" src="../assets/scene2-coins/coin-platinum.svg" alt="coin-platinum" #load="onImgLoad">
<img class="coin-gold" src="../assets/scene2-coins/coin-gold.svg" alt="coin-gold" #load="onImgLoad">
<img class="coin-diamond" src="../assets/scene2-coins/coin-diamond.svg" alt="coin-diamond" #load="onImgLoad">
</div>
</template>
`
SCSS:
`
<style lang="scss" scoped>
.js-loading *,
.js-loading *:before,
.js-loading *:after {
animation-play-state: paused !important;
}
div {
display: flex;
justify-content: center;
align-items: center;
perspective: 500px;
perspective-origin: 50% 50%;
img {
position: inherit;
display: block;
}
///////////////////////////// BACKGROUND
.circle-bg {
min-width: 1200px;
min-height: 1200px;
// animation: circle-bg 1000ms linear both 2000ms;
animation-name: circle-bg;
animation-duration: 1000ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes circle-bg {
0% { transform: rotate(180deg) scale3D(.65); }
25% { transform: rotate(180deg) scale3D(.7375); }
50% { transform: rotate(180deg) scale3D(.825); }
75% { transform: rotate(180deg) scale3D(.9125); }
100% { transform: rotate(180deg) scale3D(1); }
}
.circle-bg--2 {
min-width: 1500px;
min-height: 1500px;
// animation: circle-bg--2 1500ms linear both 2000ms;
animation-name: circle-bg--2;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes circle-bg--2 {
0% { transform: translate3D(0, 0, -3000px); }
25% { transform: translate3D(0, 0, -2250px); }
50% { transform: translate3D(0, 0, -1500px); }
75% { transform: translate3D(0, 0, -750px); }
100% { transform: translate3D(0, 0, 0px); }
}
///////////////////////////// STARS & CONFETTI
.stars {
// animation: stars 1500ms linear both 2000ms;
animation-name: stars;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes stars {
0% { transform: translateZ(-500px); }
100% { transform: translateZ(500px); }
}
.confetti {
width: 50px;
height: 50px;
top: 120px;
left: 250px;
// animation: confetti 1500ms linear both 2000ms;
animation-name: confetti;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes confetti {
0% { transform: translateZ(-500px); filter: blur(0px); }
100% { transform: translateZ(500px); filter: blur(2px); }
}
.confetti--2 {
width: 100px;
height: 100px;
top: 480px;
left: 20px;
// animation: confetti--2 1500ms linear both 2000ms;
animation-name: confetti--2;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes confetti--2 {
0% { transform: skew(-20deg, 10deg) translateZ(-500px); filter: blur(0px); }
100% { transform: skew(-20deg, 10deg) translateZ(500px); filter: blur(2px); }
}
///////////////////////////// COINS
#mixin all-coins {
width: 100px;
height: 100px;
}
.coin-diamond {
#include all-coins;
top: 330px;
left: 180px;
// animation: coin-diamond 1500ms linear both 2000ms;
animation-name: coin-diamond;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes coin-diamond {
0% { transform: rotate(-45deg) translateZ(100px); filter: blur(0px); }
100% { transform: rotate(20deg) translateZ(1100px); filter: blur(5px); }
}
.coin-gold {
#include all-coins;
top: 300px;
left: 50px;
// animation: coin-gold 1500ms linear both 2000ms;
animation-name: coin-gold;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes coin-gold {
0% { transform: rotate(20deg) translateZ(-100px); filter: blur(0px); }
100% { transform: rotate(-40deg) translateZ(900px); filter: blur(4px); }
}
.coin-platinum {
#include all-coins;
top: 220px;
left: 200px;
// animation: coin-platinum 1500ms linear both 2000ms;
animation-name: coin-platinum;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes coin-platinum {
0% { transform: rotate(20deg) translateZ(-300px); filter: blur(0px); }
100% { transform: rotate(60deg) translateZ(700px); filter: blur(3px); }
}
.coin-silver {
#include all-coins;
top: 180px;
left: 50px;
// animation: coin-silver 1500ms linear both 2000ms;
animation-name: coin-silver;
animation-duration: 1500ms;
animation-timing-function: linear;
animation-delay: 2000ms;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: both;
}
#keyframes coin-silver {
0% { transform: rotate(0deg) translateZ(-500px); filter: blur(0px); }
100% { transform: rotate(60deg) translateZ(500px); filter: blur(2px); }
}
}
</style>
`
I've tried to optimize by adding several trick code:
display block on all
not using shorthand animation
using class animation paused until img #load is true
have tried to use will-change, but later deleted it since somebody said it's better to be used in JS - now using translate3D and scale3D (on some, haven't changed the rest of the code)
using more than 2 keyframes (on some, haven't changed the rest of the code)
btw all assets are compressed under 100kb
I suspect is the blur animation, filter blur is a GPU destroyer when you abuse of that. Hope it helps!

Nuxt scroll up before page transition

I have created a transition to be run between route changes:
.page-enter-active {
position: absolute;
width: 100%;
//max-height: 100vh;
overflow: hidden;
animation: slideScaleRight 2s ease;
}
.page-leave-active {
position: absolute;
width: 100%;
//max-height: 100vh;
overflow: hidden;
animation: scaleSlideRight 2s ease;
}
#keyframes scaleSlideRight {
0% {
transform: scale(1);
}
33% {
transform: scale(0.75) translateX(0);
opacity: 0.5;
}
66% {
transform: scale(0.75) translateX(150%);
}
100% {
transform: scale(0.75) translateX(150%);
}
}
#keyframes slideScaleRight {
0% {
transform: scale(0.75) translateX(-150%);
}
33% {
transform: scale(0.75) translateX(-150%);
}
66% {
opacity: 0.5;
transform: scale(0.75) translateX(0);
}
100% {
transform: scale(1) translateX(0);
}
}
The transition run smooth but I just discover that if the page is not at top position, before leaving, nuxt force an scroll to the top making the experience really bad...
I can guess nuxt is scrolling up before triggering the transition and I really would like to keep the page where it is before leaving.
Any ideas?
You could set scrollToTop: false on an upper page (or even in /layouts/default.vue?) to prevent the scrolling of the page as shown in the documentation.
If you want more granularity, you could also look into scrollBehavior.

Stop padding left text animation

I have this code to slide to left 10px my h2: It works but after the text is moved It returns to 0 padding left. How I can stop the animation?
Thanks.
.bg_slider:hover h2 {
animation: myanim-in 3s 1;
}
#keyframes myanim-in {
50% {
padding-left: 10px;
}
You can use transition effects instead of animation.
I add a testable example below.
.bg_slider h2 {
transition: 1s;
}
.bg_slider:hover h2 {
padding-left: 10px;
}
<div class="bg_slider">
<h2>Heading</h2>
</div>

I want to create a custom loader in ionic 4 ,but in the message feild it is showing html code ,but not rendering my gif image

async presentLoading() {
const loading = await this.loader.create({
duration: 2000,
showBackdrop:false,
cssClass:'sa',
spinner:'false',
message:`
<div class="custom-spinner-container">
<img class="loading" width="120px" height="120px" src="assets/loader1.gif" />
</div>`
});
return await loading.present();
}
You can just simply achieve it with css
//Header of file
import { LoadingController } from "#ionic/angular";
//In the constructor
constructor(public loadingCtrl: LoadingController) {
}
async showLoader () {
this.loader = await this.loadingCtrl.create({
cssClass: 'custom-loader',
spinner: null
});
await this.loader.present();
}
/* Inside global.scss
You can create amazing gifs with
https://loading.io/animation
*/
.custom-loader {
--background: transparent;
ion-backdrop {
background-color: #fff;
opacity: .9 !important;
}
.loading-wrapper {
-webkit-animation: ld-vortex-out 2s ease-out infinite;
animation: ld-vortex-out 2s ease-out infinite;
animation-timing-function: cubic-bezier(0.05, 0, 3, 0.05);
background-image: url("/assets/img/baubap-logo-circle.svg");
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
min-width: 90px;
min-height: 90px;
box-shadow: none;
-webkit-box-shadow: none;
}
}
#keyframes ld-vortex-out {
0% {
-webkit-transform: rotate(0deg) scale(0);
transform: rotate(0deg) scale(0);
opacity: 1;
}
60% {
-webkit-transform: rotate(1800deg) scale(1);
transform: rotate(1800deg) scale(1);
opacity: 1;
}
100% {
-webkit-transform: rotate(1800deg) scale(1);
transform: rotate(1800deg) scale(1);
opacity: 0;
}
}
#-webkit-keyframes ld-vortex-out {
0% {
-webkit-transform: rotate(0deg) scale(0);
transform: rotate(0deg) scale(0);
opacity: 1;
}
60% {
-webkit-transform: rotate(1800deg) scale(1);
transform: rotate(1800deg) scale(1);
opacity: 1;
}
100% {
-webkit-transform: rotate(1800deg) scale(1);
transform: rotate(1800deg) scale(1);
opacity: 0;
}
}
Result
Baubap loader screen
So did you check documentation?
In Ionic 3 it was a different syntax and it was not supposed to change:
https://ionicframework.com/docs/api/components/loading/LoadingController/
See their example - use different value for hiding default spinner...
Try this:
async presentLoading() {
const loading = await this.loader.create({
duration: 2000,
showBackdrop:false,
cssClass:'sa',
spinner:'hide',
message:`
<div class="custom-spinner-container">
<img class="loading" width="120px" height="120px" src="assets/loader1.gif" />
</div>`
});
return await loading.present();
}
Update: seems like in Ionic 4 suggested way to deal with loader animation is via ion-spinner. But its unclear if the old way should break or is just not supported yet in Beta

Aurelia router animation

I'm using au-animate in each view to make a page transition:
the current view slides left out (from center to left) and the next view slides left in (from right to center).
#keyframes slideLeftIn {
0% {transform: translate(100%, 0);}
100% {transform: translate(0, 0);}
}
#keyframes slideLeftOut {
0% {transform: translate(0, 0);}
100% {transform: translate(-100%, 0);}
}
.pages.au-enter-active {
animation: slideLeftIn 0.8s;
}
.pages.au-leave-active {
animation: slideLeftOut 0.8s;
}
Based on: Aurelia router view animation with swap-order="with"
Now, I need to have both views in the DOM during the transition, like in W3 slide.
Is there a way to achieve this in aurelia?
UPDATE:
It appears to be a bug preventing this:
error aurelia-templating-router 1.0.1 with swap-order
UPDATE2:
In the last release this bug was fixed! Aurelia rocks.
#keyframes slideLeftIn {
0% {
-webkit-transform: translate(100%, 0);
transform: translate(100%, 0); }
100% {
-webkit-transform: none;
transform: none; } }
#keyframes slideLeftOut {
0% {
-webkit-transform: none;
transform: none; }
100% {
-webkit-transform: translate(-100%, 0);
transform: translate(-100%, 0); } }