I have implemented animation pausing as described here:
How to pause and resume CSS3 animation using JavaScript?
Here is my CSS for the rotating element:
.is-rotating{
-webkit-animation: circle 55s linear infinite;
-moz-animation: circle 55s linear infinite;
-ms-animation: circle 55s linear infinite;
animation: circle 55s linear infinite;
}
I toggle a is-paused class to the elements in question onmouseover:
.is-paused{
-webkit-animation-play-state:paused;
-moz-animation-play-state:paused;
-o-animation-play-state:paused;
animation-play-state:paused;
}
When I remove this class with JS (onmouseout), the rotating animation resets to the 'origin' point. Sometimes it does, sometimes not. This happens in webkit (Chrome and Safari on OSX), works fine in FF.
I know animation-play-state is an experimental feature, but MDN says it should work fine in webkit. Does anyone have any ideas on how to implement for webkit browsers?
UPDATE: here is the rest of the CSS:
#-webkit-keyframes circle {
from { -webkit-transform:rotate(0deg); }
to { -webkit-transform:rotate(360deg); }
}
#-webkit-keyframes inner-circle {
from { -webkit-transform:rotate(0deg); }
to { -webkit-transform:rotate(-360deg); }
}
#-moz-keyframes circle {
from { -moz-transform:rotate(0deg); }
to { -moz-transform:rotate(360deg); }
}
#-moz-keyframes inner-circle {
from { -moz-transform:rotate(0deg); }
to { -moz-transform:rotate(-360deg); }
}
#-ms-keyframes circle {
from { -ms-transform:rotate(0deg); }
to { -ms-transform:rotate(360deg); }
}
#-ms-keyframes inner-circle {
from { -ms-transform:rotate(0deg); }
to { -ms-transform:rotate(-360deg); }
}
#keyframes circle {
from { transform:rotate(0deg); }
to { transform:rotate(360deg); }
}
#keyframes inner-circle {
from { transform:rotate(0deg); }
to { transform:rotate(-360deg); }
}
Have you tried animation-fill-mode: forwards? That specifies that at the end of the animation, it should maintain its final styles instead of reverting to its pre-animation state.
I've experienced similar issues with a CSS animation in Webkit browsers as well. The issue, in my situation, was that I was using the css transform property, like so:
#keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(20px); }
100% { transform: translateY(0px); }
}
This caused glitching/jumping when pausing/playing the animation with the animation-play-state property. Replacing transform with top fixed this jumping issue in webkit browsers.
#keyframes float {
0% { top: 0px; }
50% { top: 20px; }
100% { top: 0px; }
}
I had the same flavor of jumpiness using CSS to animate a 3D carousel product catalog
In two directions based on :hover.
Having fiddled with obvious ideas like animation-fill-mode:forwards and such
with not the least good fortunes what finally solved it was to mix in two bits of transition syntax with a tiny duration and the transform itself as the property. In the course of transition chasing to catch transform's state ,it's updates
To the element being transformed remained intact , and the effect seems to fit the specs , so it should be a valid solution
transition-duration: 0.2s;transition-property:transform;
Related
I'm doing some CSS animations inside a modal dialog. Here's the pertinent SCSS:
#keyframes grow {
from {
transform: scale(1);
}
to {
transform: scale(1.1);
}
}
#keyframes shrink {
from {
transform: scale(1.1);
}
to {
transform: scale(1);
}
}
$duration: 0.5s;
$animationFillMode: both;
&:not(.active):hover, &.active {
img {
animation: grow $duration $animationFillMode;
}
}
&:not(.active) {
img {
animation: shrink $duration $animationFillMode;
}
}
This works well but the problem is, when I open the modal, the animations kick in immediately. For example, because when the modal is first open I'm not hovering on one of the elements, the element instantly shrinks from big to small. I want the element to start in the small state when the modal is open.
Is is possible? TIA
Yes it is, use reverse tag.
Example: animation-direction: reverse;
I am facing a challenge to make a dynamic 'hinting' system. I would like to make an element blink using only CSS. Not sure if it even possible. Normally you should define the begin and end color of your animation (update: This is not true.), but because I would like to let it work on multiple background colours this isn't an option.
I have tried a number of options and Google queries (inherit, currentColor etc.) but all it does is go from white/transparent to #ef9633.
Anyone got some options I could try?
Code:
#keyframes nk-hint {
0% { background-color: #XXX; }
50% { background-color: #ef9633; }
100% { background-color: #XXX; }
}
#-webkit-keyframes nk-hint {
0% { background-color: #XXX; }
50% { background-color: #ef9633; }
100% { background-color: #XXX; }
}
Thanks allot already!
The answer was simpler than I thought. You can just remove the 0% and 100% and it works fine on all major browser. Still need to test this on iOS and IE.
It's safe to say you don't need to set a begin and/or end colour.
#keyframes nk-hint {
50% { background-color: #ef9633; }
}
#-webkit-keyframes nk-hint {
50% { background-color: #ef9633; }
}
animation-fill-mode can do what you want, unless you need to support IE < 9. http://www.w3schools.com/cssref/css3_pr_animation-fill-mode.asp
If you need IE 9 support, then I believe you're stuck with Javascript for the animation unfortunately.
Ok then, you could make the changes as shown below.
.your-selector {
background-color: red;
-webkit-animation: nk-hint 3s; /* Chrome, Safari, Opera */
-webkit-animation-iteration-count: 1; /* Chrome, Safari, Opera */
-webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */
animation: nk-hint 3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#-webkit-keyframes nk-hint {
0% {background-color: #XXX;}
50% {background-color: #ef9633;}
100% {background-color: #XXX;}
}
#keyframes nk-hint {
0% {background-color: #XXX;}
50% {background-color: #ef9633;}
100% {background-color: #XXX;}
}
The keyframes will remain the same.
I have an animation that has an infinite iterations count:
.spinner {
animation: spinnerAnimation 2s linear infinite;
}
What I want is to make the animation finish the current animation cycle and stop it on a button click (not really on a button click, but this is to make things easier to understand):
$("button").click(function() {
$(".spinner").addClass("stop");
})
This will add a stop class to the spinner:
.spinner.stop {
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
It doesn't work really smooth, but I don't care about smoothness much in this case:
http://codepen.io/Deka87/pen/OXZvdm
The only problem is that this won't stop the animation in IE edge, i.e. things don't work in IE (versions that support animations). Any ideas?
PS: animation-play-state: pause; is not what I need, because this won't make the animation finish the current animation cycle, but pause it in its current position instead.
PSS: I am really looking for a CSS only solution, i.e. make it work inside .spinner.stop{}.
You had a problem with the name of your keyframe name - spinnerAnimation vs preloaderAnimation
The only way I was able to set IE to stop the animation was to set animation: none; inside the .stop class:
$("button").click(function() {
$(".spinner").addClass("stop");
})
.spinner {
width: 30px; height: 30px;
background: green;
animation: spinnerAnimation 2s linear infinite;
}
.spinner.stop {
-webkit-animation-iteration-count: 1;
animation: none;
}
button {
margin-top: 20px;
}
#-webkit-keyframes spinnerAnimation {
0% {
-webkit-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spinnerAnimation {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="spinner"></div>
<button>Stop spinner</button>
Hello I am having trouble combining both css transition and animations together. The animation is working but some reason when I add a transition, the transition works, but cancels out the animation. Anyone know how to combine them?
Here is my CSS:
.circle-spin {
transition: all 1s ease;
}
.circle-spin-reverse {
transition: all 1s ease;
}
.success li:hover .circle-spin-reverse {
animation:spin-reverse 10s linear infinite;
/* the above works until i add the transition below */
transform:scale(1.25);
}
.success li:hover .circle-spin {
animation:spin 10s linear infinite;
/* the above works until i add the transition below */
transform:scale(1.25);
}
#keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
#keyframes spin-reverse { 100% { -webkit-transform: rotate(360deg); transform:rotate(-360deg); } }
Sorry I know it's alot of code, but thats the bare minimum code needed for this question.
Thanks
It’s cause your transform
/* in :hover */
transform:scale(1.25);
overrides transform in animaton
/* in animation */
transform:rotate(360deg);
You have to separate transforms to different elements. See my codepen.
I used a snippet from here a while back to create a infinitely scrolling element https://css-tricks.com/infinite-all-css-scrolling-slideshow/
The active code I'm using on my website looks like:
.wave_bg {
background: url("../img/wave_bg.jpg") no-repeat;
-webkit-animation: slide 10s linear infinite;
-moz-animation: slide 10s linear infinite;
-ms-animation: slide 10s linear infinite;
animation: slide 10s linear infinite;
}
#-webkit-keyframes slide {
from {
background-position: 0 0;
}
to {
background-position: 100% 0;
}
}
#-moz-keyframes slide {
from {
background: left;
}
to {
background: right;
}
}
#-ms-keyframes slide {
from {
background: left;
}
to {
background: right;
}
}
#keyframes slide {
from {
background: left;
}
to {
background: right;
}
}
However in Chrome 34 this suddenly stopped working (it worked in Chrome 33 and earlier) - the background image just doesn't appear at all (it works in FF 33.1, FF 35.0.1, FF 38.0.5 and IE 10 still). If I disable the animation (and deprecated -webkit-animation) in dev tools then the background image shows again - so I'm assuming the issue is related to the CSS animation.
I can't find (at a quick search around) any documentation on things changing in Chrome 34 with regards to animations - so I was wondering if anyone had experienced this bug and had some sort of workaround for it?
I haven't looked at your code.. but... as Chrome drops more and more prefixes, some of your animations may not work if for example your only using -webkit prefixes in you -webkit-animation: infinite....
Make sure you use both prefixed and unprefixed syntax within your delcared animations basically. See below...
You need this...
#-webkit-keyframes infnite {
0% { -webkit-transform: scale(1); transform: scale(1);}
100% { -webkit-transform: scale(2); transform: scale(1);}
}
and this...
#keyframes infnite {
0% { -webkit-transform: scale(1); transform: scale(1);}
100% { -webkit-transform: scale(2); transform: scale(1);}
}
In the above example... if Chrome dropped support for transform prefix but not for keyframes then unless u have both the prefix and unprefix your animation will stop working "suddenly".