I recently built this little demo where three elements are continuously spinning until you click in one of them and then it moves for the middle of the screen and gets bigger. Here's the CSS:
.spin {
animation-name: spin;
animation-duration: 0.9s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-play-state: running;
animation-fill-mode: backwards;
animation-delay: 0s;
}
.selected {
cursor: auto;
animation-name: spin, selected;
animation-duration: 0.9s, 1s;
animation-timing-function: linear, ease-out;
animation-iteration-count: infinite, 1;
animation-play-state: paused, running;
animation-fill-mode: backwards, forwards;
animation-delay: 0s, 0s;
z-index: 1;
}
#keyframes spin {
0% {
transform: translateX(150%) scale(0.5) rotate(10deg);
opacity: 0;
}
50% {
transform: translateX(0%) scale(1) rotate(0deg);
opacity: 1;
}
100% {
transform: translateX(-150%) scale(0.5) rotate(-10deg);
opacity: 0;
}
}
#keyframes selected {
to {
transform: translateY(0) scale(1.4) rotateY(180deg);
opacity: 1;
}
}
In Firefox this code works as expected: the click stops the spin animation and the element moves from where it is to the to parameter of the selected animation. In Chrome the override is less subtle, the element stops and then instantaneously appears in the middle of the screen.
I would appreciate any help with figuring out a way I could achieve this by applying one of the animations to a parent element or without overriding the transform property of the card, and also answers to why the different approach on overriding the transform property.
Related
I have a simple CSS animation which runs fine on desktop but doesn't seem to work on iPad. I have tried both Chrome and Safari.
Here's the code:
.scroll-down img {
-webkit-animation: 3s ease 0s normal none infinite running myscroll;
-moz-animation: 3s ease 0s normal none infinite running myscroll;
animation: 3s ease 0s normal none infinite running myscroll;
}
#-webkit-keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
Do I have some type of syntax error?
always add the generic - not browser specific version of css when also using the browser one ex.
#-webkit-keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
#keyframes myscroll {
0% {
opacity: 1
}
50% {
opacity: 1
}
100% {
opacity: 1;
-webkit-transform: translateY(101px);
transform: translateY(101px);
}
}
Found a solution. Apparently iPad doesnt like shorthand so I had to do this:
-webkit-animation-name: myscroll;
-webkit-animation-duration: 3s;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease;
-webkit-animation-direction: normal;
-webkit-animation-fill-mode: none;
-webkit-animation-play-state: running;
animation-name: myscroll;
animation-duration: 3s;
animation-delay: 0s;
animation-iteration-count: infinite;
animation-timing-function: ease;
animation-direction: normal;
animation-fill-mode: none;
animation-play-state: running;
I have an animation that slides an image from right to left that worked before, but has stopped working in the latest Safari and iOS.
I donĀ“t understand why?
This is the code.
.slideLeft{
overflow:hidden;
animation-play-state: paused;
-webkit-animation-play-state: paused;
animation-name: slideLeft;
-webkit-animation-name: slideLeft;
animation-duration: 1s;
-webkit-animation-duration: 1s;
animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
visibility: visible !important;
}
#keyframes slideLeft {
0% {
transform: translateX(120%);
}
100% {
transform: translateX(0%);
}
}
#-webkit-keyframes slideLeft {
0% {
-webkit-transform: translateX(120%);
}
100% {
-webkit-transform: translateX(0%);
}
}
Any input appreciated, thanks.
I have this code that spins an image when hovering:
img:hover {
-webkit-animation-name: spin;
-webkit-animation-duration: .15s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: .15s;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: .15s;
-ms-animation-iteration-count: 1;
-ms-animation-timing-function: linear;
animation-name: spin;
animation-duration: .15s;
animation-iteration-count: 1;
animation-timing-function: linear;
}
#-ms-keyframes spin {
from { -ms-transform: rotate(0deg); }
to { -ms-transform: rotate(360deg); }
}
#-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
http://jsfiddle.net/79FHN/1/
I want it to spin to the other direction when un-hovering.
How can I do this?
I can refactor your code to great extent, all you need is
Demo
img {
-webkit-transition: 1s linear;
transition: 1s linear;
}
img:hover {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
The issue with your code was, that you were using #keyframes which are nothing but animation, so once it triggers, you need to write a separate keyframe for reversing. As your animation was not so complex, I preferred using simple CSS3 properties to get the job done.
If you feel the animation nudges your icon or you deliberately want to nudge on hover, you can use transform-origin property.
Thanks to #Second Rikudo for pointing out the linear issue.
I want to have a css-coded animated rotating svg image. I have no idea how to do that. At the end it has to look exactly like this: http://baveltje.com/logo/logo.html. I am completely new to css. The rotating svg's are gear1.svg and gear2.svg. I want them to rotate 360 degres for infinite time and I want to call them <.div class="gear1"> and gear2.. Is it possible to let it look exactly like the logo does in the link, but rotating?
I tried to use jsfiddle.net/gaby/9Ryvs/7/, but with no results. It has to go the same speed like that fiddle does!
Thanks in advance!
Code:
div {
margin: 20px;
width: 100px;
height: 100px;
background: #f00;
-webkit-animation-name: spin;
-webkit-animation-duration: 4000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: 4000ms;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: 4000ms;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: spin;
animation-duration: 4000ms;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#-ms-keyframes spin {
from { -ms-transform: rotate(0deg); }
to { -ms-transform: rotate(360deg); }
}
#-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
Here is your original animation css (I have removed prefixes to keep it simple):
#gear{
animation-name: ckw;
animation-duration: 15.5s;
}
#keyframes ckw {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
In #gear you should add:
animation-iteration-count to infinite to keep it rolling
transform-origin to center of your div 50% 50% to get gear rolling around itself
display to inline-block
Result:
#gear{
animation-name: ckw;
animation-duration: 15.5s;
/* Things added */
animation-iteration-count: infinite;
transform-origin: 50% 50%;
display: inline-block;
/* <--- */
}
#keyframes ckw {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
And of course add correct prefixes.
I've come across this post//
Slide out text from an image using CSS on hover
The CSS works perfectly, except I would like for the animation to stop after it's rotated once.
Is this possible? If so how can I accomplish this?
HTML:
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(180deg);
}
to {
-webkit-transform: rotate(0deg);
}
}
#-moz-keyframes rotate {
from {
-moz-transform: rotate(180deg);
}
to {
-moz-transform: rotate(0deg);
}
}
.srch_btn:hover {
-webkit-animation-name: rotate;
-webkit-animation-duration: 0.5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: rotate;
-moz-animation-duration: 0.5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
}
Change animation-iteration-count: infinite to 2.