.box1{
width:200px;
height:200px;
background-color: #FFF8DC;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
}
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
#-webkit-keyframes moving-image {
from { -webkit-transform: rotate(0deg) scale(1);
}
to { -webkit-transform: rotate(360deg) scale(1.3);}
}
<div class='box1'></div>
When you hover over a box I want it to increase its size and rotate it 360 degrees once. When you remove the cursor from the box I want it to go back to its original shape. I have put my code below and I don't know what's wrong with it.
.box1{
width:200px;
height:200px;
background-color: #FFF8DC;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
}
#-webkit-keyframes moving-image {
from { -webkit-transform: rotate(0deg) scale(1);
}
to { -webkit-transform: rotate(360deg) scale(1.3);}
}
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
I think I have what you're looking for:
There is no need for webkit keyframes & all of that stuff. All I did was add a :hover effect and a css transition (which makes the spin effect)
.box1{
width:200px;
height:200px;
background-color: red;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
transition: all ease 1s;
}
.box1:hover{
transform: rotate(360deg) scale(1.3);
}
<div class="box1"></div>
Edit:
Your version would've worked fine as well if you change the
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
to
.box1:hover {
-webkit-animation: moving-image 2s 1;
}
Both can be done with transform, like so:
.myClass {
transform: scale(1.3) rotate(360deg);
}
but to be on the safe side, you should take care of older browsers:
.myClass {
-moz-transform: scale(1.3) rotate(360deg);
-webkit-transform: scale(1.3) rotate(360deg);
-o-transform: scale(1.3) rotate(360deg);
-ms-transform: scale(1.3) rotate(360deg);
transform: scale(1.3) rotate(360deg);
}
The last line should be the standard css3 directive.
Related
As you can see in the below animation, if you hover out then the animation stops abruptly. I would like to transition it to the final position down. Is there a way to do it while keeping keyframes?
.bounce{
width:100px;
height:100px;
background:red;
margin-top:100px;
}
.bounce:hover {
animation-name: bounce;
animation-duration: 1s;
animation-fill-mode: both;
animation-iteration-count: infinite;
}
#keyframes bounce {
0%, 100%, 20%, 50%, 80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0)
}
40% {
-webkit-transform: translateY(-30px);
-ms-transform: translateY(-30px);
transform: translateY(-30px)
}
60% {
-webkit-transform: translateY(-15px);
-ms-transform: translateY(-15px);
transform: translateY(-15px)
}
}
<div class="bounce"></div>
I want to implement something like this:
img{
transition: 5s linear;
transform: scale(2,2) rotate(-20deg) rotate(40deg) rotate(-40deg) rotate(20deg) scale(0.5, 0.5);
}
But is just scales a bit and then scales back to the original size.
You simply have to create an element and add to it animation using keyframes, as in the example below:
.element {
animation: rotate 5s infinite;
width: 50px;
height: 50px;
background-color: green;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
25% {
transform: rotate(20deg);
}
50% {
transform: rotate(-20deg);
}
75% {
transform: rotate(20deg);
}
100% {
transform: rotate(-20deg);
}
}
<div class="element"> </div>
You can find more information about it here: https://css-tricks.com/almanac/properties/a/animation/
I recommend you to use animation over transition.
#keyframes{
0%{
//your transform
}
50%{
//your transform
}
100%{
//your transform
}
}
I have this css :
.yellowText {
color: #FFFF00;
-ms-transform: rotate(-20deg); /* IE 9 */
-webkit-transform: rotate(-20deg); /* Chrome, Safari, Opera */
transform: rotate(-20deg);
}
.pulse {
-webkit-animation: text-anim;
animation: text-anim 1s;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out;
animation-iteration-count:infinite;
-webkit-animation-iteration-count:infinite;
}
#-webkit-keyframes text-anim {
0% { -webkit-transform: scale(1); }
50% { -webkit-transform: scale(1.1); }
100% { -webkit-transform: scale(1); }
}
#keyframes text-anim {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
Then, I apply it to a text :
<p class="yellowText pulse">Some text here</p>
But now, the text is well-animated, without being rotated by -20°... Any idea of what could be wrong ? I believe this is a problem with the transform property not working with the animation one. Also, what I tried was putting the transform inside the #keyframes text-anim, but what this does is just periodically rotating the text, having it perfectly right the rest of the time...
Thanks in advance for your help !
PS : forgive my bad English, I'm French :P
Your #keyframes are overriding you original transform property.
#-webkit-keyframes text-anim {
0% { -webkit-transform: scale(1 rotate(-20deg); }
50% { -webkit-transform: scale(1.1) rotate(-20deg); }
100% { -webkit-transform: scale(1) rotate(-20deg); }
}
#keyframes text-anim {
0% { transform: scale(1) rotate(-20deg); }
50% { transform: scale(1.1) rotate(-20deg); }
100% { transform: scale(1) rotate(-20deg); }
}
Why isn't transform: scale(0); working on a animated element?
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
#box {
width: 150px;
height: 150px;
background: red;
animation: spin .5s infinite linear;
transform: scale(0);
}
I guess its because the keyframe take over transform, but even with !important after transform: scale(0) its still not changing.
http://jsfiddle.net/yun0xu8t/1/
You need to move transform: scale(0); to #keyframes
To rotate and scale together
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg) scale(0); }
}
This is the fiddle.I have searched a solution for this but didn't find one. The correct one should be the one in Chrome/Opera/Safari. I want to show only the image from top to bottom.
The HTML:
<div class="container">
<img class="image" src="http://www.hotel-aramis.com/slider/home/notre-dame-de-paris.jpg" />
</div>
The CSS:
#-webkit-keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
#keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
.container {
position:relative;
width:1100px;
height:480px;
overflow:hidden;
background-color:#000;
}
.image {
position:absolute;
top: 0;
max-width:100%;
min-width:100%;
-webkit-animation: pan 5s alternate infinite linear;
animation: pan 5s alternate infinite linear;
}
Firefox doesn't use webkit why your -webkit-transform will do nothing. Change it to transform and it should most likely work.
I made a JSFiddle for you
#-webkit-keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
#keyframes pan {
0% {
transform: translate(0%, 0%);
}
100% {
top: 100%;
transform: translate(0%, -100%);
}
}