I know there are many examples how to spin a icon with CSS and stuff but somehow I can't achieve what I want.
<button id="button" mat-button type="button" class="fa-spin-hover" (click)="doSomething()">
<fa-icon [icon]="['fas', 'sync']" [spin]="false" size="lg" class="rotate">
</fa-icon>
</button>
I don't know what's the best practice here. Of course I could create a boolean value and do something like [spin]="bool" but I don't think thats the right way. If I use class="fa-spin-hover" on the button the whole button spins but it works. If I use it on <fa-icon> it does not work.
.fa-spin-hover:hover {
-webkit-animation: fa-spin 2s 1 linear;
-moz-animation: fa-spin 2s 1 linear;
-o-animation: fa-spin 2s 1 linear;
animation: fa-spin 2s 1 linear;
}
I tried several things. Thats also why the attribute class="rotate" is on <fa-icon>. I tried to only have a 180 degree spin on hovering:
.rotate:hover {
animation: rotate 1s ease-in-out 0s;
}
#keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(180deg);
}
}
But these classes are useless on <fa-icon>. Also tried things like ::ng-deep
Created a StackBlitz: https://stackblitz.com/edit/angular-font-awesome-starter-msp1vu
I am using CSS & HTML to flip the image on hover, but how can I flip image for 1 second after loading?
You can set a keyframe animation on a 1-second delay. The forwards makes sure the style from the animation is kept.
.flip {
animation: flip-animation .25s 1s forwards;
-webkit-animation: flip-animation .25s 1s forwards; /* for less modern browsers */
}
#keyframes flip-animation {
// code to flip the
from {}
to{}
}
I'm working with ngAnimate to show animations on screen transitions in my angular app. We are using ui-router.
What I want is to have the login screen slide upwards off the screen to reveal the next screen, after the user logs in successfully. How can I apply the .ng-leave class to only the login screen?
Here's the useful code I've got so far:
login-directive.html:
<div class="login-slide" id="login-slide">
<div class="viewport-1">
<header></header>
<background></background>
<login-form callLogin="login(username, password)"></login-form>
<version-footer></version-footer>
</div>
styles.css:
#keyframes slideOutUp {
0% {
transform: translate(0px, 400px);
}
100% {
transform: translate(0, -600px);
}
}
.login-slide.ng-leave {
-webkit-animation: slideOutUp 3s ease;
-moz-animation: slideOutUp 3s ease;
-o-animation: slideOutUp 3s ease;
animation: slideOutUp 3s ease;
}
#login-slide.ng-leave {
-webkit-animation: slideOutUp 3s ease;
-moz-animation: slideOutUp 3s ease;
-o-animation: slideOutUp 3s ease;
animation: slideOutUp 3s ease;
}
From everything I've seen, this should be enough to get the login-slide class to "slide" away when the login is complete because the login screen would be leaving the DOM at that time.
I'm also very open to using a combo of ng-class, ng-if, or any other directives if that would help.
Thanks!
A couple things:
1) You need to use some type of angular directive on the element you're trying to animate. In this case it looks like ng-view would be your best option since you're using ui-router. Here's a good example.
2) .ng-leave is the state of the element at the start of the animation. You need to have its finished state as well: .ng-leave-active. (Also in the example above)
Hope that helps.
I want to use the advantage of the css animation ability of doing infinite action to control the child I target each time in a different value THEN at some point go back to the zero and so.
Lets say I want to color the background of a group of 3 DIVs, So the CSS code will be:
<style>
div:nth-of-type(1){
-webkit-animation:coloring 2s infinite;
}
#-webkit-keyframes coloring{
from {background:red;}
to {background:yellow;}
}
<style>
So as long as I used infinite property it will go forever and here I want to increase the value of nth-of-type each time in a row (1,2,3) then when reaching the 3 it will back to 1
Very interesting question. But i don't think CSS support a loop function.
:nth-of-type() can calculate different index but the results will be disabled as one array selection:
:nth-of-type(0,1,2,3). This doesn't support any iteration, all the elements will be selected at once.
This is however possible in javascript/jQuery, as it supports iterations:
var count = 0;
var delay = 0;
$('div').each(function()
{
$('div:eq(' + count +')').delay(delay)
.queue(function()
{
$(this).css('background', 'yellow');
})
count++;
delay += 500;
})
It will iterate every div element. Whith the .eq() selector, every element based on the index value will be selected, this way every element is selected one by one.
Normally this would excecute in seconds, so you wouldn't see the effect of "one-by-one".
I used a delay() to have a delay on the selector, where the delay will be increased at every iteration. In this case after every half second a new .queue() will be added so the each function will not iterate before the queue has been finished.
combined this with the css transition to get the fade-in effect:
transition: background 2s;
-webkit-transition: background 2s; /* Safari */
jsFiddle
Try this:
HTML:
<div class="div active"></div>
<div class="div"></div>
<div class="div"></div>
CSS:
.active {
-webkit-animation:coloring 3s;
}
JS:
var len = $(".div").length;
setTimeout(function () {
change_bg();
},3000);
function change_bg() {
var index = $(".active").index(); // get index of active div
var current;
$(".active").removeClass("active");
if (index == len - 1) { // check if active div is last
current = 0; // if last then start from first
} else {
current = index + 1; // increment otherwise
}
$(".div:eq(" + current + ")").addClass("active"); //change background of next div
setTimeout(function () { //recursive calling
change_bg();
},3000);
}
Fiddle here.
I was reviewing my questions and I wanted to share a different approach to achieve this with pure CSS:
#keyframes coloring {
0% {
background:red;
}
25% {
background:yellow;
}
33% {
background:#ccc;
}
75% {
background:#ccc;
}
100%{
background:#ccc;
}
}
.div {
height:50px;
background:#ccc;
}
.first {
-webkit-animation:coloring 9s ease-out 0s infinite;
animation:coloring 9s ease-out 0s infinite;
-moz-animation:coloring 9s ease-out 0s infinite;
-webkit-animation:coloring 9s ease-out 0s infinite;
}
.second {
-webkit-animation:coloring 9s ease-out 3s infinite;
animation:coloring 9s ease-out 3s infinite;
-moz-animation:coloring 9s ease-out 3s infinite;
-webkit-animation:coloring 9s ease-out 3s infinite;
}
.third {
-webkit-animation:coloring 9s ease-out 6s infinite;
animation:coloring 9s ease-out 6s infinite;
-moz-animation:coloring 9s ease-out 6s infinite;
-webkit-animation:coloring 9s ease-out 6s infinite;
}
<div class="div first"></div>
<div class="div second"></div>
<div class="div third"></div>
I'm making a simple landing page driven by CSS3. To make it look awesome there's an <a> plopping up:
#keyframes splash {
from {
opacity: 0;
transform: scale(0, 0);
}
50% {
opacity: 1;
transform: scale(1.1, 1.1);
}
to {
transform: scale(1, 1);
}
}
And to make it even more awesome I added a hover animation:
#keyframes hover {
from {
transform: scale(1, 1);
}
to {
transform: scale(1.1, 1.1);
}
}
But there comes the problem! I assigned the animations like this:
a {
/* Some basic styling here */
animation: splash 1s normal forwards ease-in-out;
}
a:hover {
animation: hover 1s infinite alternate ease-in-out;
}
Everything works just fine: The <a> splashes into the users face and has a nice vibration when he hovers it. Bit as soon as the user blurs the <a> the smooth stuff ends abruptly and the <a> repeats the splash-animation. (Which is logical to me, but I don't want it to)
Is there some way to solve this problem without some JavaScript Class Jiggery Pokery?
After hours of googling: No, it's not possible without JavaScript. The animation-iteration-count: 1; is internally saved in the animation shothand attribute, which gets resetted and overwritten on :hover. When we blur the <a> and release the :hover the old class reapplies and therefore again resets the animation attribute.
There sadly is no way to save a certain attribute states across element states.
You'll have to use JavaScript.
If I understand correctly that you want to play the animation on A only once you have to add
animation-iteration-count: 1
to the style for the a.
It can be done with a little bit of extra overhead.
Simply wrap your link in a div, and separate the animation.
the html ..
<div class="animateOnce">
<a class="animateOnHover">me!</a>
</div>
.. and the css ..
.animateOnce {
animation: splash 1s normal forwards ease-in-out;
}
.animateOnHover:hover {
animation: hover 1s infinite alternate ease-in-out;
}
I just got this working on Firefox and Chrome. You just add/remove the below class accordingly to your needs.
.animateOnce {
-webkit-animation: NAME-OF-YOUR-ANIMATION 0.5s normal forwards;
-moz-animation: NAME-OF-YOUR-ANIMATION 0.5s normal forwards;
-o-animation: NAME-OF-YOUR-ANIMATION 0.5s normal forwards;
}
Just use
animation: hover 1s ease-in-out forwards;
An easy solution to solve this problem is by just adding more seconds to the animation in a:hover and taking advantage of the transitions in #keyframes
a:hover {
animation: hover 200s infinite alternate ease-in-out;
}
Just make the progression of #keyframes go faster by using percentages.
#keyframes hover {
0% {
transform: scale(1, 1);
}
1% {
transform: scale(1.1, 1.1);
}
100% {
transform: scale(1.1, 1.1);
}
}
200 seconds or 300 seconds in the animation is more than enough to make sure the animation doesn't restart. A normal person won't last more than a few seconds hovering an image.
Impossible in CSS only, you need a javascript workaround. As already explained by some here, the animation-iteration-count property is reset on a :hover. The best is to do everything in javascript, but for reasons of ease of customization of the code you may want to keep the possibility of doing something in CSS.
So, in JS :
// adding a class to the html tag, during the animation time
const startPage = (() => {
const html = document.documentElement,
s = 'start'
html.classList.add(s)
window.addEventListener('load', function() {
setTimeout(() => {
html.classList.remove(s)
}, 1500) // the time must be at least equal to the duration of the CSS animation (personally I put a little more).
})
})()
And for the CSS:
/* the presence of the `.start` class conditions the animation */
.start .leaflet-marker-pane {
animation: animDrop 1s ease;
}
The following code without "iteration-count: 1" was resulting in all line items pulsing after entering, until the last item loaded, even though 'pulse was not being used.
<li class="animated slideInLeft delay-1s animation-iteration-count: 1"><i class="fa fa-credit-card" aria-hidden="true"></i> 1111</li>
<li class="animated slideInRight delay-1-5s animation-iteration-count: 1"><i class="fa fa-university" aria-hidden="true"></i> 222222</li>
<li class="animated lightSpeedIn delay-2s animation-iteration-count: 1"><i class="fa fa-industry" aria-hidden="true"></i> aaaaaa</li>
<li class="animated slideInLeft delay-2-5s animation-iteration-count: 1"><i class="fa fa-key" aria-hidden="true"></i> bbbbb</li>
<li class="animated slideInRight delay-3s animation-iteration-count: 1"><i class="fa fa-thumbs-up" aria-hidden="true"></i> ccccc</li>
So i just found a solution for that:
In the hover animation do this:
animation: hover 1s infinite alternate ease-in-out,splash 1;