Spin or rotate an image on hover - css

I want to find out how to make a spinning or rotating image when it is hovered. I would like to know how to emulate that functionality with CSS on the following code :
img {
border-radius: 50%;
}
<img src="http://i.imgur.com/3DWAbmN.jpg" />

You can use CSS3 transitions with rotate() to spin the image on hover.
Rotating image :
img {
transition: transform .7s ease-in-out;
}
img:hover {
transform: rotate(360deg);
}
<img src="https://i.stack.imgur.com/BLkKe.jpg" width="100" height="100"/>
Here is a fiddle DEMO
More info and references :
a guide about CSS transitions on MDN
a guide about CSS transforms on MDN
browser support table for 2d transforms on caniuse.com
browser support table for transitions on caniuse.com

It's very simple.
You add an image.
You create a css property to this image.
img { transition: all 0.3s ease-in-out 0s; }
You add an animation like that:
img:hover
{
cursor: default;
transform: rotate(360deg);
transition: all 0.3s ease-in-out 0s;
}

if you want to rotate inline elements, you should set the inline element to inline-block first.
i {
display: inline-block;
}
i:hover {
animation: rotate-btn .5s linear 3;
-webkit-animation: rotate-btn .5s linear 3;
}
#keyframes rotate-btn {
0% {
transform: rotate(0);
}
100% {
transform: rotate(-360deg);
}
}

Here is my code, this flips on hover and flips back off-hover.
CSS:
.flip-container {
background: transparent;
display: inline-block;
}
.flip-this {
position: relative;
width: 100%;
height: 100%;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-container:hover .flip-this {
transition: 0.9s;
transform: rotateY(180deg);
}
HTML:
<div class="flip-container">
<div class="flip-this">
<img width="100" alt="Godot icon" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Godot_icon.svg/512px-Godot_icon.svg.png">
</div>
</div>
Fiddle this

here is the automatic spin and rotating zoom effect using css3
#obj1{
float:right;
width: 96px;
height: 100px;
-webkit-animation: mymove 20s infinite; /* Chrome, Safari, Opera */
animation: mymove 20s infinite;
animation-delay:2s;
background-image:url("obj1.png");
transform: scale(1.5);
-moz-transform: scale(1.5);
-webkit-transform: scale(1.5);
-o-transform: scale(1.5);
-ms-transform: scale(1.5); /* IE 9 */
margin-bottom: 70px;
}
#obj2{
float:right;
width: 96px;
height: 100px;
-webkit-animation: mymove 20s infinite; /* Chrome, Safari, Opera */
animation: mymove 20s infinite;
animation-delay:2s;
background-image:url("obj2.png");
transform: scale(1.5);
-moz-transform: scale(1.5);
-webkit-transform: scale(1.5);
-o-transform: scale(1.5);
-ms-transform: scale(1.5); /* IE 9 */
margin-bottom: 70px;
}
#obj6{
float:right;
width: 96px;
height: 100px;
-webkit-animation: mymove 20s infinite; /* Chrome, Safari, Opera */
animation: mymove 20s infinite;
animation-delay:2s;
background-image:url("obj6.png");
transform: scale(1.5);
-moz-transform: scale(1.5);
-webkit-transform: scale(1.5);
-o-transform: scale(1.5);
-ms-transform: scale(1.5); /* IE 9 */
margin-bottom: 70px;
}
/* Standard syntax */
#keyframes mymove {
50% {transform: rotate(30deg);
}
<div style="width:100px; float:right; ">
<div id="obj2"></div><br /><br /><br />
<div id="obj6"></div><br /><br /><br />
<div id="obj1"></div><br /><br /><br />
</div>

Related

Auto scrolling (snapping) text with CSS only?

At the moment I have a CSS autoscrolling text that looks like this:
.vscroll {
position: absolute;
height: auto;
/* Starting position */
-moz-transform:translateY(100%);
-webkit-transform:translateY(100%);
transform:translateY(100%);
/* Apply animation to this element */
-moz-animation: scroll-up 25s linear infinite;
-webkit-animation: scroll-up 25s linear infinite;
animation: scroll-up 25s linear infinite;
}
/* Move it (define the animation) */
#-moz-keyframes scroll-up {
0% { -moz-transform: translateY(100%); }
100% { -moz-transform: translateY(-100%); }
}
#-webkit-keyframes scroll-up {
0% { -webkit-transform: translateY(100%); }
100% { -webkit-transform: translateY(-100%); }
}
#keyframes scroll-up {
0% {
-moz-transform: translateY(100%); /* Browser bug fix */
-webkit-transform: translateY(100%); /* Browser bug fix */
transform: translateY(100%);
}
100% {
-moz-transform: translateY(-100%); /* Browser bug fix */
-webkit-transform: translateY(-100%); /* Browser bug fix */
transform: translateY(-100%);
}
}
This works, but it does look a bit choppy on some devices. So I am hoping it is possible to do something like this but with only CSS instead of jQuery: https://www.jqueryscript.net/demo/Vertical-Text-Scrolling-Plugin-With-jQuery-scrollText-js/
Is it possible?
Hope this will help (Sample).
<!DOCTYPE html>
<title>Example</title>
<!-- Styles -->
<style>
.example1 {
height: 50px;
overflow: hidden;
position: relative;
}
.example1 h3 {
font-size: 3em;
color: limegreen;
position: absolute;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
/* Apply animation to this element */
-moz-animation: example1 15s linear infinite;
-webkit-animation: example1 15s linear infinite;
animation: example1 15s linear infinite;
}
/* Move it (define the animation) */
#-moz-keyframes example1 {
0% { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
#-webkit-keyframes example1 {
0% { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
#keyframes example1 {
0% {
-moz-transform: translateX(100%); /* Firefox bug fix */
-webkit-transform: translateX(100%); /* Firefox bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Firefox bug fix */
-webkit-transform: translateX(-100%); /* Firefox bug fix */
transform: translateX(-100%);
}
}
</style>
<!-- HTML -->
<div class="example1">
<h3>Scrolling text... </h3>
</div>

css animation ignores rotation

I am trying to make an animation, where few elements would appear bigger than they are and shrink back to normal.
Here's what I've got:
One of the elements
#element {
position: absolute;
width: 38%;
height: auto;
animation: ani 250ms ease-in;
-webkit-animation: ani 250ms ease-in;
transform: rotate(82deg);
}
And keyframe
#keyframes ani {
0% {
transform: scale(1.5);
-webkit-transform: scale(1.5);
}
100% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
HTML
<div id="wrapper">
<img id="element" src="img.svg">
<img id="element2" src="img2.svg">
</div>
The problem is that whenever the animation starts, elements appear as they never been rotated and rotates only after animation ends. How could I force them to rotate before the animation?
you should combine the rotation code with transform in animation as well. basically rotate and scale both are the values of transform property, so if you only use scale in the animation, it will override rotate value and will only show the scale.
#element {
position: absolute;
width: 38%;
height: auto;
animation: ani 250ms ease-in;
-webkit-animation: ani 250ms ease-in;
transform: rotate(82deg);
}
#keyframes ani {
0% {
transform: scale(1.5) rotate(82deg);
-webkit-transform: scale(1.5) rotate(82deg);
}
100% {
transform: scale(1.0) rotate(82deg);
-webkit-transform: scale(1.0) rotate(82deg);
}
}
<div id="wrapper">
<img id="element" src="https://pbs.twimg.com/profile_images/604644048/sign051.gif">
<img id="element2" src="http://smallbusinessbc.ca/wp-content/themes/sbbcmain/images/circle-icons/icon-education.svg">
</div>
You need to move your rotate into the keyframes:
#element {
position: absolute;
width: 38%;
height: auto;
animation: ani 250ms ease-in;
-webkit-animation: ani 250ms ease-in;
}
#keyframes ani {
0% {
transform: scale(1.5) rotate(0deg);
-webkit-transform: scale(1.5) rotate(0deg);
}
100% {
transform: scale(1.0) rotate(82deg);
-webkit-transform: scale(1.0) rotate(82deg);
}
}

CSS3 animation fails to work in firefox

This animation isn't working in firefox, however it works fine in chrome, any ideas what might be wrong? Thanks!
CSS
.modular-template-wrapper .two-col-two-rows-img-txt-ocapi .sk-spinner-three-bounce div {
width: 8px;
height: 8px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
background-color: #000;
display: inline-block;
-webkit-animation: sk-threeBounceDelay 1.4s infinite ease-in-out;
animation: sk-threeBounceDelay 1.4s infinite ease-in-out;
/* Prevent first frame from flickering when animation starts */
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
/* line 203, ../../sass/modules/qv-overlay.scss */
.modular-template-wrapper .two-col-two-rows-img-txt-ocapi .sk-spinner-three-bounce .sk-bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
/* line 206, ../../sass/modules/qv-overlay.scss */
.modular-template-wrapper .two-col-two-rows-img-txt-ocapi .sk-spinner-three-bounce .sk-bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
#-webkit-keyframes sk-threeBounceDelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
}
40% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
#keyframes sk-threeBounceDelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
}
40% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
HTML
<div class="sk-spinner sk-spinner-three-bounce">
<div class="sk-bounce1"></div> <div class="sk-bounce2"></div>
<div class="sk-bounce3"></div>
</div>

Internet Explorer 11 wobbly CSS3 animation

Please refer to this fiddle: http://jsfiddle.net/eQegA/3/
<div class="spinner"></div>
.spinner {
width: 100px;
height: 100px;
border: 50px solid blue;
/*border-top-color: #fff;
border-bottom-color: #fff;*/ /* commented out to see the wobble better */
border-radius: 200px;
-webkit-animation: application-loading-rotate 1s;
animation: application-loading-rotate 1s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
#-webkit-keyframes application-loading-rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#keyframes application-loading-rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
In Google Chrome the rotation is stable, however for some reason in IE11 there is a noticable "wobble" of the circle as it rotates.
Any ideas why it wobbles so? Is there any way to fix it in IE11?
For what it's worth, it also occurs on other browsers. It has to do, how the border is drawn, it's not a perfect round. As far as I know, there isn't a quick fix for this. However you can draw the border as a background image.
.spinner {
display:block;
width: 200px;
height: 200px;
border-radius: 100%;
background-image:url(http://www.clipartbest.com/cliparts/9iR/RyK/9iRRyKLie.png);
background-size:100%;
-webkit-animation: application-loading-rotate 1s;
animation: application-loading-rotate 1s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
#-webkit-keyframes application-loading-rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#keyframes application-loading-rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
See:
http://jsfiddle.net/eQegA/26/

Creating this rotating animation using CSS

This is the animation I'd like to make using CSS.
It is an animated PNG. Firefox is the only browser I know that will show the animation. Please view this in FireFox so you can see the animation. I'd like to try and make it in CSS so I can use it in more browsers and still get true transparency (which animated gifs can't provide)
<-- Here is a single one of the dots, which could be used to make the animation without having to create the dot's shading in css.
This fiddle http://jsfiddle.net/jvrvK/ shows what I've got so far. I sorta have the look of the spheres, but the animation doesn't seem to work in Chrome and I don't understand CSS animations enough to create the same type of rotation in the PNG.
Thanks very much for any help!
Fiddle code below:
<ul class="busy">
<li class="busy-dot1"><b class="busy-dot-shine"></b></li>
<li class="busy-dot2"><b class="busy-dot-shine"></b></li>
<li class="busy-dot3"><b class="busy-dot-shine"></b></li>
<li class="busy-dot4"><b class="busy-dot-shine"></b></li>
<li class="busy-dot5"><b class="busy-dot-shine"></b></li>
</ul>
.busy {
list-style: none;
padding: 0;
position: relative;
transform-style: preserve-3d;
animation: rot 4s linear infinite;
width:100px;
}
.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
border-radius: 50%;
display: inline-block;
transform-style: preserve-3d;
margin: 0 4px;
}
.busy-dot-shine {
display: block;
border-radius: 50%;
background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
background-color: #193987;
animation: rotr 4s linear infinite;
height: 20px;
width: 20px;
}
Chrome can be fussy about prefixes, add PrefixFree library to your code. You could add the prefixes yourself, but I find PreFix Free much easier.
//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js
http://jsfiddle.net/adrianjmartin/jvrvK/2/
Another way would be to use SVG:
http://jsfiddle.net/adrianjmartin/AcvE5/3/
This would be an aproximate solution
demo
The HTML is the same that you had; the CSS is
.busy {
list-style: none;
padding: 0;
position: relative;
width:100px;
}
.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
border-radius: 50%;
display: inline-block;
position: absolute;
left: 150px;
top: 50px;
-webkit-animation: rot 4s linear infinite;
animation: rot 4s linear infinite;
}
.busy-dot2 {
-webkit-animation-delay: -3.5s;
animation-delay: -3.5s;
}
.busy-dot3 {
-webkit-animation-delay: -3s;
animation-delay: -3s;
}
.busy-dot4 {
-webkit-animation-delay: -2.7s;
animation-delay: -2.7s;
}
.busy-dot-shine {
display: block;
border-radius: 50%;
background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
background-color: #193987;
height: 20px;
width: 20px;
}
.busy-dot2 .busy-dot-shine {
height: 15px;
width: 15px;
}
.busy-dot3 .busy-dot-shine {
height: 10px;
width: 10px;
}
.busy-dot4 .busy-dot-shine {
height: 6px;
width: 6px;
}
#-webkit-keyframes rot {
0% {-webkit-transform: scaleX(2) rotate(0deg) translateX(50px) scale(1) rotate(0deg) scaleX(0.5);
opacity: 0.5;}
25% {-webkit-transform: scaleX(2) rotate(90deg) translateX(50px) scale(1.5) rotate(-90deg) scaleX(0.5);
opacity: 0.8;}
50% {-webkit-transform: scaleX(2) rotate(180deg) translateX(50px) scale(1) rotate(-180deg) scaleX(0.5);
opacity: 0.5;}
75% {-webkit-transform: scaleX(2) rotate(270deg) translateX(50px) scale(0.8) rotate(-270deg) scaleX(0.5);
opacity: 0.2;}
100% {-webkit-transform: scaleX(2) rotate(360deg) translateX(50px) scale(1) rotate(-360deg) scaleX(0.5);
opacity: 0.5;}
}
#keyframes rot {
0% {transform: scaleX(2) rotate(0deg) translateX(50px) scale(1) rotate(0deg) scaleX(0.5);
opacity: 0.5;}
25% {transform: scaleX(2) rotate(90deg) translateX(50px) scale(1.5) rotate(-90deg) scaleX(0.5);
opacity: 0.8;}
50% {transform: scaleX(2) rotate(180deg) translateX(50px) scale(1) rotate(-180deg) scaleX(0.5);
opacity: 0.5;}
75% {transform: scaleX(2) rotate(270deg) translateX(50px) scale(0.8) rotate(-270deg) scaleX(0.5);
opacity: 0.2;}
100% {transform: scaleX(2) rotate(360deg) translateX(50px) scale(1) rotate(-360deg) scaleX(0.5);
opacity: 0.5;}
}
The trick is to set a transform that scales in X 2 times (to generate an elipse when rotated), then rotates and translates to make a circle.
Then apply a scale to make the circles grow, and at last counter-rotate to make the sphere look right
Of course, all the values are aproximate, the GIF is too small to tell if that is accurate
HTML:
<div id="all">
<div id="box">
<div id="circle"></div>
</div>
<div id="box" class="box2">
<div id="circle" class="circle2"></div>
</div>
<div id="box" class="box3">
<div id="circle" class="circle3"></div>
</div>
<div id="box" class="box4">
<div id="circle" class="circle4"></div>
</div>
<div id="box" class="box5">
<div id="circle" class="circle5"></div>
</div>
</div>
CSS:
#box {
position: absolute;
width: 50px;
height: 50px;
}
.box2 {
-webkit-transform: rotate(35deg);
}
.box3 {
-webkit-transform: rotate(70deg);
}
.box4 {
-webkit-transform: rotate(105deg);
}
.box5 {
-webkit-transform: rotate(140deg);
}
.circle2 {
-webkit-transform: scale(.8);
}
.circle3 {
-webkit-transform: scale(.6);
}
.circle4 {
-webkit-transform: scale(.4);
}
.circle5 {
-webkit-transform: scale(.2);
}
#circle {
position: relative;
top: 0px;
left: 50px;
border-radius: 50%;
background: radial-gradient(circle at 25% 25%, #FFF, rgba(255, 255, 255, 0));
background-color: #193987;
animation: rotr 4s linear infinite;
height: 20px;
width: 20px;
}
#all {
position: relative;
top: 50px;
left: 50px;
width: 50px;
height: 50px;
animation: myfirst;
animation-duration: 05s;
animation-timing-function: linear;
animation-iteration-count: infinite;
-webkit-animation-name: myfirst;
-webkit-animation-duration: 05s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
}
#keyframes myfirst {
0% { transform: rotate(360deg);}
}
#-webkit-keyframes myfirst {
0% { -webkit-transform: rotate(360deg);}
}
Live demo
HTML:
<ul class="busy">
<li class="busy-dot1"><b class="busy-dot-shine"></b></li>
</ul>
CSS:
.busy {
list-style: none;
padding: 0;
position: relative;
transform-style: preserve-3d;
animation: rot 4s linear infinite;
width:700px;
}
.busy-dot1, .busy-dot2, .busy-dot3, .busy-dot4, .busy-dot5 {
border-radius: 50%;
display: inline-block;
transform-style: preserve-3d;
margin: 0 4px;
}
.busy-dot-shine {
display: block;
border-radius: 50%;
background: radial-gradient(circle at 25% 25%, #FFF, rgba(255,255,255,0));
background-color: #193987;
animation: rotr 4s linear infinite;
height: 60px;
width: 60px;
}
.busy li
{
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* IE 9 */
-webkit-transform:rotate(7deg); /* Safari and Chrome */
animation:rotate 5s linear infinite;
-webkit-animation:rotate 5s linear infinite; /* Safari and Chrome */
}
#keyframes rotate
{
from {transform:rotate(0deg);
-ms-transform:rotate(0deg); /* IE 9 */
-webkit-transform:rotate(0deg); /* Safari and Chrome */}
to {transform:rotate(-180deg);
-ms-transform:rotate(-180deg); /* IE 9 */
-webkit-transform:rotate(-180deg); /* Safari and Chrome */}
}
#-webkit-keyframes rotate /* Safari and Chrome */
{
from {transform:rotate(0deg);
-ms-transform:rotate(0deg); /* IE 9 */
-webkit-transform:rotate(0deg); /* Safari and Chrome */}
to {transform:rotate(-360deg);
-ms-transform:rotate(-360deg); /* IE 9 */
-webkit-transform:rotate(-360deg); /* Safari and Chrome */}
}
See in action: http://jsfiddle.net/Ld9pP/1/
You'll probably choose the other one but whatever

Resources