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'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've got an HTML element here with this starting style:
transition: transform 2s;
First, it is animated (it rotatesX) via a class that is added on click. On the next click, another class is added that adds a transform3d that should move the element vertically and this should take 2 seconds as per the rule above.
The transform3d doesn't take effect unless I add this rule to the element: animation: none as well. I am confused on what animation: none actually does. Are there complications with transforming an element that has had an animation applied to it?
animation: none sets all animate-* properties to their initial value:
animation-name: none;
animation-duration: 0s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: none;
animation-play-state: running;
The problem is that your element has an animation which affects its transform property. Therefore, when you modify its static transform, you don't see the change because it's overridden by the animation.
Then, if you remove the animation, you see the change in transform.
This is unrelated to transforms, it would happen with any property, like color:
div {
animation: color-anim 1s infinite;
}
#keyframes color-anim {
from { color: red }
to { color: blue }
}
<div>Lorem ipsum</div>
<button onclick="document.querySelector('div').style.color = '#fff'">Make white</button>
<button onclick="document.querySelector('div').style.animation = 'none'">Remove animation</button>
Okay heres my .css
.centerhex {
background-image:url(http://i.imgur.com/4sZDtfK.png);
height:224px;
width:210px;
position:absolute;
opacity:0;
transition:opacity 2s ease-in-out;
}
.transtart{
opacity:0
}
#-webkit-keyframes fadein {
0%{opacity:0;}
40%{opacity:1;}
50%{opacity:1;}
100%{opacity:0.05;}
}
#keyframes fadein {
0%{opacity:0;}
40%{opacity:1;}
50%{opacity:1;}
100%{opacity:0.05;}
}
.done{
animation-delay:0.5s;
-webkit-animation-delay:0.5s;
}
.fadein{
animation:fadein 0.65s;
animation-timing-function:linear;
animation-fill-mode:forwards;
animation-iteration-count:1;
-webkit-animation-iteration-count:1;
-webkit-animation:fadein 0.65s;
-webkit-animation-timing-function:linear;
-webkit-animation-fill-mode: forwards;
}
#-webkit-keyframes pulse {
0%{opacity:0.05;}
10%{opacity:0.1;}
100%{opacity:0.05;}
}
#keyframes pulse {
0%{opacity:0.05;}
10%{opacity:0.1;}
100%{opacity:0.05;}
}
.pulse{
animation:fadein 4s;
animation-timing-function:linear;
animation-fill-mode:forwards;
animation-iteration-count:infinite;
animation-delay:1s
-webkit-animation-delay:1s;
-webkit-animation-iteration-count:infinite;
-webkit-animation:fadein 4s;
-webkit-animation-timing-function:linear;
-webkit-animation-fill-mode: forwards;
}
What I was curious about is if it is possible to create an id specifically for nesting predefined classes, such as:
#hexa.centerhex.transtart.fadein.done
So far experiments in doing this have failed.. so Im not entirely sure what Im doing wrong.
The idea I have for this is that Im going to be creating some script that replaces an ID with another ID. For instance I would make:
#hexa.centerhex.transtart.fadein.done
Turn into:
#hexb.centerhex.transtart.pulse.done
You can do what you're asking but it seems like you're hoping for an unrealistic result based on the ordering of your classes that you typed out. The rendering won't go in a certain order based on selectors you choose unfortunately.
However, this can be done with Javascript fairly easily using a setTimeout() if timing was an issue.
And if you don't care about the order of operations on these classes being added to each id, then you should be able to do this as much as you want (and with reasonably high success as the #id is only trumped by !important and client-side/browser settings).
Don't forget your semicolons :)
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;