How do I do the inverse animation when I "hover off" the .child element (css3 only if possible)?
Fiddle
HTML:
<div class="child">
<i class="fa fa-video-camera spin" style="font-size:22px;"></i>
</div>
CSS:
.child:hover .spin{
-webkit-animation: spin 0.2s linear;
-moz-animation: spin 0.2s linear;
-o-animation: spin 0.2s linear;
animation: spin 0.2s linear;
}
#-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);
}
}
The easiest way would be to use transition instead of keyframes:
.child .spin {
transition: transform .2s linear;
}
.child:hover .spin{
transform: rotate(360deg);
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="child">
<i class="fa fa-video-camera spin" style="font-size:22px;"></i>
</div>
Comes with auto-reverse built in. Much less code.
Don't use animation, use transition
<div class="camera"></div>
<style>
.camera{
height: 100px;
width: 50px;
background-color: red;
transition: 2s;
}
.camera:hover{
transform: rotate(360deg);
}
</style>
Fiddle
Well, you can do that. But you'll need a default animation too.
.child{
margin-top:20px;
margin-left:20px;
}
.child .spin{
-webkit-animation: spin 0.5s ease-in-out;
-moz-animation: spin 0.5s ease-in-out;
-o-animation: spin 0.5s ease-in-out;
animation: spin 0.5s ease-in-out;
}
.child:hover .spin{
-webkit-animation: spinh 0.5s ease-in-out;
-moz-animation: spinh 0.5s ease-in-out;
-o-animation: spinh 0.5s ease-in-out;
animation: spinh 0.5s ease-in-out;
}
#-moz-keyframes spin {
from {
-moz-transform: rotate(360deg);
}
to {
-moz-transform: rotate(0deg);
}
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(360deg);
}
to {
-webkit-transform: rotate(0deg);
}
}
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#-webkit-keyframes spinh {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#keyframes spinh {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
<div class="child">
<i class="fa fa-video-camera spin" style="font-size:22px;"></i>
</div>
See the working example.
Related
I tried CSS scale transition ease-out not working, but the images do not scale yet.
An image is worth a thousand words. You will understanding easily the image. I also provide the snippet code box.
The 3 left images scale decreasing themselves and slide/ease from right to left and out and the 3 right images scale decreasing themselves and slide/ease from left to right and out.
Run the snippet box as you can see there is the space between a red image and the image do not scale. And the images are not aligned.
.sliding-images
{
align-items: center;
display: flex;
flex-flow: row nowrap;
height: 70%;
justify-content: center;
}
.sliding-images img
{
transition: transform 1s;
-webkit-transition: transform 1s;
width: 12%;
}
.sliding-images img:nth-child(1)
{
transform: scale(1.1) translateX(270%);
-webkit-transform: scale(1.1) translateX(270%);
transform-origin: right;
-webkit-transform-origin: right;
z-index: 1;
-webkit-animation: slide-left 0.15s ease-out both;
animation: slide-left 0.15s ease-out both;
}
.sliding-images img:nth-child(2)
{
transform: scale(1.2) translateX(178%);
-webkit-transform: scale(1.2) translateX(178%);
transform-origin: right;
-webkit-transform-origin: right;
z-index: 2;
-webkit-animation: slide-left 0.10s ease-out both;
animation: slide-left 0.10s ease-out both;
}
.sliding-images img:nth-child(3)
{
transform: scale(1.3) translateX(-87%);
transform: scale(1.3) translateX(-87%);
transform-origin: right;
-webkit-transform-origin: right;
z-index: 3;
-webkit-animation: slide-left 0.5s ease-out both;
animation: slide-left 0.5s ease-out both;
}
.sliding-images img:nth-child(4)
{
transform: scale(1.4);
-webkit-transform: scale(1.4);
z-index: 4;
}
.sliding-images img:nth-child(5)
{
transform: scale(1.3) translateX(-87%);
-webkit-transform: scale(1.3) translateX(-87%);
transform-origin: left;
-webkit-transform-origin: left;
z-index: 3;
-webkit-animation: slide-right 0.5s ease-out both;
animation: slide-right 0.5s ease-out both;
}
.sliding-images img:nth-child(6)
{
transform: scale(1.2) translateX(-178%);
-webkit-transform: scale(1.2) translateX(-178%);
transform-origin: left;
-webkit-transform-origin: left;
z-index: 2;
-webkit-animation: slide-right 0.10s ease-out both;
animation: slide-right 0.10s ease-out both;
}
.sliding-images img:nth-child(7)
{
transform: scale(1.1) translateX(-270%);
-webkit-transform: scale(1.1) translateX(-270%);
transform-origin: left;
-webkit-transform-origin: left;
z-index: 1;
-webkit-animation: slide-right 0.15s ease-out both;
animation: slide-right 0.15s ease-out both;
}
#-webkit-keyframes slide-left {
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(-100px);
transform: translateX(-100px);
}
}
#keyframes slide-left {
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(-100px);
transform: translateX(-100px);
}
}
#-webkit-keyframes slide-right
{
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(100px);
transform: translateX(100px);
}
}
#keyframes slide-right
{
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(100px);
transform: translateX(100px);
}
}
<div class="sliding-images">
<img src="https://via.placeholder.com/432x864/fdc34f/FEFEFE?text=1">
<img src="https://via.placeholder.com/432x864/3e72ff/FEFEFE?text=2">
<img src="https://via.placeholder.com/432x864/222222/FEFEFE?text=3">
<img src="https://via.placeholder.com/432x864/fe7b7b/FEFEFE?text=4">
<img src="https://via.placeholder.com/432x864/24d366/FEFEFE?text=5">
<img src="https://via.placeholder.com/432x864/afd33c/FEFEFE?text=6">
<img src="https://via.placeholder.com/432x864/41c8b8/FEFEFE?text=7">
</div>
You must use calc to calculate exact width and translateX positions.
see edited code snipped.
.sliding-images
{
position:absolute;
align-items: center;
display: flex;
flex-flow: row nowrap;
height: 70%;
justify-content: center;
}
.sliding-images img
{
transition: transform 1s;
-webkit-transition: transform 1s;
width: calc(100%/7);
}
.sliding-images img:nth-child(1)
{
transform-origin: right;
-webkit-transform-origin: right;
z-index: 1;
-webkit-animation: slide-left 0.15s ease-out both,scale11 0.1s both;
animation: slide-left 0.15s ease-out both,scale11 0.1s both;
}
.sliding-images img:nth-child(2)
{
transform: scale(1.2) translateX(178%);
-webkit-transform: scale(1.2) translateX(178%);
transform-origin: right;
-webkit-transform-origin: right;
z-index: 2;
-webkit-animation: slide-left 0.10s ease-out both,scale12 0.1s both;
animation: slide-left 0.10s ease-out both,scale12 0.1s both;
}
.sliding-images img:nth-child(3)
{
transform: scale(1.3) translateX(-87%);
transform: scale(1.3) translateX(-87%);
transform-origin: right;
-webkit-transform-origin: right;
z-index: 3;
-webkit-animation: slide-left 0.5s ease-out both,scale13 0.1s both;
animation: slide-left 0.5s ease-out both,scale13 0.1s both;
}
.sliding-images img:nth-child(4)
{
transform: scale(1.4);
-webkit-transform: scale(1.4);
z-index: 4;
}
.sliding-images img:nth-child(5)
{
transform: scale(1.3) translateX(-87%);
-webkit-transform: scale(1.3) translateX(-87%);
transform-origin: left;
-webkit-transform-origin: left;
z-index: 3;
-webkit-animation: slide-right 0.5s ease-out both,scale13 0.1s both;
animation: slide-right 0.5s ease-out both,scale13 0.1s both;
}
.sliding-images img:nth-child(6)
{
transform-origin: left;
-webkit-transform-origin: left;
z-index: 2;
-webkit-animation: slide-right 0.10s ease-out both,scale12 0.1s both;
animation: slide-right 0.10s ease-out both,scale12 0.1s both;
}
.sliding-images img:nth-child(7)
{
transform-origin: left;
-webkit-transform-origin: left;
z-index: 1;
-webkit-animation: slide-right 0.15s ease-out both,scale11 0.1s both;
animation: slide-right 0.15s ease-out both,scale11 0.1s both;
}
#-webkit-keyframes slide-left {
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(calc(-100%/7));
transform: translateX(calc(-100%/7));
}
}
#keyframes slide-left {
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(calc(-100%/7));
transform: translateX(calc(-100%/7));
}
}
#-webkit-keyframes slide-right
{
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(calc(100%/7));
transform: translateX(calc(100%/7));
}
}
#keyframes slide-right
{
0% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
100% {
-webkit-transform: translateX(calc(100%/7));
transform: translateX(calc(100%/7));
}
}
#keyframes scale11
{
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
}
#keyframes scale12
{
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
}
#keyframes scale13
{
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
-webkit-transform: scale(1.3);
transform: scale(1.3);
}
}
<div class="sliding-images">
<img src="https://via.placeholder.com/432x864/fdc34f/FEFEFE?text=1">
<img src="https://via.placeholder.com/432x864/3e72ff/FEFEFE?text=2">
<img src="https://via.placeholder.com/432x864/222222/FEFEFE?text=3">
<img src="https://via.placeholder.com/432x864/fe7b7b/FEFEFE?text=4">
<img src="https://via.placeholder.com/432x864/24d366/FEFEFE?text=5">
<img src="https://via.placeholder.com/432x864/afd33c/FEFEFE?text=6">
<img src="https://via.placeholder.com/432x864/41c8b8/FEFEFE?text=7">
</div>
I use this code to create a blinking zoom-in and zoom-out image, but it only zoom-in and after that, it reset image and again zoom-in.
#keyframes blink {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
}
img {
transition: .3s ease-in;
animation: blink 1s;
animation-iteration-count: infinite;
}
JSFiddle
Easy solution would be:
#keyframes blink {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
img {
transition: .3s ease-in;
animation: blink 1s;
animation-iteration-count: infinite;
}
So you just need in the end of animation make image same position as it is at start. : )
You have to animate it to the start point again. Like this:
#keyframes blink {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
img {
transition: .3s ease-in;
animation: blink 1s;
animation-iteration-count: infinite;
}
I would like to make a simple animation, when the page loads, my logo should animate from the left side of the box to the right side. I have tried many versions, but haven't succeeded yet.
HTML
<body>
<div>
<img src="logo.png" alt="logo" style="width:170px;height:120px;">
</div>
</body>
CSS
div
{
width:640px;
height:175px;
background:blue;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
position:absolute;
}
div img
{
-webkit-transform: translate(3em,0);
-moz-transform: translate(3em,0);
-o-transform: translate(3em,0);
-ms-transform: translate(3em,0);
}
Try using keyframes.
div {
width: 50px;
height: 40px;
background: blue;
position: relative;
left: 500px;
-webkit-animation: slideIn 2s forwards;
-moz-animation: slideIn 2s forwards;
animation: slideIn 2s forwards;
}
#-webkit-keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
#-moz-keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
#keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
<div></div>
You need to use animation instead of transition. Transition effects are triggered on certain events, for example a click which adds a class or a hover.
div img {
animation: example 1s ease-in-out forwards;
}
#keyframes example {
from {transform: transition(0,0)}
to {transform: transition(3em,0)}
}
Now you would of course have to add the prefixes for that, webkit, moz, etc.
For basic knowledge about keyframe animation in css3:
http://www.w3schools.com/css/css3_animations.asp
After checking out I implemented below code but the effect is not happening, don't know where its lacking..
<style>
.rotate {
-webkit-transition: -webkit-transform 0.4s ease-in-out;
-moz-transition: -moz-transform 0.4s ease-in-out;
-o-transition: -o-transform 0.4s ease-in-out;
-ms-transition: -ms-transform 0.4s ease-in-out;
transition: transform 0.4s ease-in-out;
cursor:pointer;
}
.rotate:hover {
color:#afafaf;
-webkit-transform: rotateZ(360deg);
-moz-transform: rotateZ(360deg);
-ms-transform: rotateZ(360deg);
-o-transform: rotateZ(360deg);
transform: rotateZ(360deg);
}
</style>
HTML
<div class="col-lg-6 col-md-6 col-sm-12">
<h2 align="center"> <icon class="icon icon-rocket icon-2x "> </icon> <br />
Build your Resume </h2>
</div>
Edit: changed the rotate CLASS from icon to parent
It will work with animation:
<div class="col-lg-6 col-md-6 col-sm-12">
<h2 align="center"> <icon class="icon icon-rocket icon-2x "> </icon> <br />
Build your Resume </h2>
</div>
CSS:
.rotate {
cursor:pointer;
}
.rotate:hover {
color:#afafaf;
-moz-animation: spin .4s 1 linear;
-o-animation: spin .4s 1 linear;
-webkit-animation: spin .4s 1 linear;
animation: spin .4s 1 linear;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(359deg); }
}
#-moz-keyframes spin {
0% { -moz-transform: rotate(0deg); }
100% { -moz-transform: rotate(359deg); }
}
#-o-keyframes spin {
0% { -o-transform: rotate(0deg); }
100% { -o-transform: rotate(359deg); }
}
#-ms-keyframes spin {
0% { -ms-transform: rotate(0deg); }
100% { -ms-transform: rotate(359deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(359deg); }
}
<img class="image" src="" alt="" width="120" height="120">
Cannot get this animated image to work, it is supposed to do a 360 degrees rotation.
I guess something's wrong with the CSS below, as it just stays still.
.image {
float: left;
margin: 0 auto;
position: absolute;
top: 50%;
left: 50%;
width: 120px;
height: 120px;
margin-top: -60px;
margin-left: -60px;
-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 a demo. The correct animation CSS:
.image {
position: absolute;
top: 50%;
left: 50%;
width: 120px;
height: 120px;
margin:-60px 0 0 -60px;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
}
#-moz-keyframes spin {
100% { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform:rotate(360deg);
}
}
<img class="image" src="http://i.stack.imgur.com/pC1Tv.jpg" alt="" width="120" height="120">
Some notes on your code:
You've nested the keyframes inside the .image rule, and that's incorrect
float:left won't work on absolutely positioned elements
Have a look at caniuse: IE10 doesn't need the -ms- prefix
To achieve the 360 degree rotation, here is the Working Solution.
The HTML:
<img class="image" src="your-image.png">
The CSS:
.image {
overflow: hidden;
transition-duration: 0.8s;
transition-property: transform;
}
.image:hover {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
}
You have to hover on the image and you will get the 360 degree rotation effect.
PS: Add a -webkit- extension for it to work on chrome and other webkit browers. You can check the updated fiddle for webkit HERE
I have a rotating image using the same thing as you:
.knoop1 img{
position:absolute;
width:114px;
height:114px;
top:400px;
margin:0 auto;
margin-left:-195px;
z-index:0;
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
overflow:hidden;
}
.knoop1:hover img{
-webkit-transform:rotate(360deg);
-moz-transform:rotate(360deg);
-o-transform:rotate(360deg);
}
try this easy
.btn-circle span {
top: 0;
position: absolute;
font-size: 18px;
text-align: center;
text-decoration: none;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
}
.btn-circle span :hover {
color :silver;
}
/* rotate 360 key for refresh btn */
#-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
#-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
#keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
<button type="button" class="btn btn-success btn-circle" ><span class="glyphicon">↻</span></button>
if you want to flip image you can use it.
.image{
width: 100%;
-webkit-animation:spin 3s linear infinite;
-moz-animation:spin 3s linear infinite;
animation:spin 3s linear infinite;
}
#-moz-keyframes spin { 50% { -moz-transform: rotateY(90deg); } }
#-webkit-keyframes spin { 50% { -webkit-transform: rotateY(90deg); } }
#keyframes spin { 50% { -webkit-transform: rotateY(90deg); transform:rotateY(90deg); } }
The another method to rotate an object in the background using css3, check out the below css3 code here:
.floating-ball-model-3 > span {
animation-name: floating-ball-model-3;
animation-duration: 7s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: floating-ball-model-3;
-webkit-animation-duration: 7s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: floating-ball-model-3;
-moz-animation-duration: 7s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: floating-ball-model-3;
-ms-animation-duration: 7s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
-o-animation-name: floating-ball-model-3;
-o-animation-duration: 7s;
-o-animation-iteration-count: infinite;
-o-animation-timing-function: linear;
}
#keyframes floating-ball-model-3 {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Here this should help you
The below jsfiddle link will help you understand how to rotate a image.I used the same one to rotate the dial of a clock.
http://jsfiddle.net/xw89p/
var rotation = function (){
$("#image").rotate({
angle:0,
animateTo:360,
callback: rotation,
easing: function (x,t,b,c,d){
return c*(t/d)+b;
}
});
}
rotation();
Where:
• t: current time,
• b: begInnIng value,
• c: change In value,
• d: duration,
• x: unused
No easing (linear easing):
function(x, t, b, c, d) { return b+(t/d)*c ; }