I am trying to achieve an infinite blink and rotation together, but the problem I face is quite weird, the blinking which should occur at a regular interval of 500ms, happens nicely for a while then disappears and appears back again.
Also I went through lot of questions around blinking but my test case is different. I can't keep the 0% 50% 100% in the keyframes to get the blinking working because I'd want the span to blink at a particular percentage I specify.
For example: I'd want the span to blink at 100deg or 90deg, so I should be able to specify the blink timing by specifying the exact percentage value.
Here's my work so far, any help would be appreciated. http://jsfiddle.net/8UQ8X/7/ (includes vendor prefixes)
<div>
<span></span>
</div>
<style>
div{
position: fixed;
width:3px;
height:100px;
left: 300px;
top: 100px;
border: 1px rgba(255,255,255,0.1) solid;
-webkit-animation: spin 500ms steps(30) infinite;
-webkit-transform-origin: center center;
-webkit-transform: translate3d(0, 0, 0);
}
span{
display:block;
width: 2px;
height: 2px;
border-radius: 50%;
-webkit-animation: blink 500ms infinite steps(1);
}
#-webkit-keyframes spin {
from{
-webkit-transform: rotate(0deg)
}
to{
-webkit-transform: rotate(360deg)
}
}
#-webkit-keyframes blink {
// I should be able to any percentage value to get the span blink at a particular degree.
// for now I am trying to blink the span at 0%, the beginning, later I might change it to 50% or something
0% {background: #fff}
1% {background: none;}
}
body{
background: #232323;
}
</style>
Try this : Animation
.i{
position: fixed;
width:10px;
height:150px;
left: 300px;
top: 100px;
border: 1px rgba(255,255,255,0.1) solid;
-webkit-animation: spin 500ms steps(30) infinite;
-webkit-transform-origin: center center;
-webkit-transform: translate3d(0, 0, 0);
-moz-animation: spin 500ms steps(30) infinite;
-moz-transform-origin: center center;
-moz-transform: translate3d(0, 0, 0);
-webkit-animation-timing-function:ease-in-out;
}
span{
display:block;
width: 10px;
height: 10px;
border: 1px rgba(255,255,255,0.1) solid;
border-radius: 50%;
-webkit-animation: blink 500ms infinite steps(1);
-moz-animation: blink 500ms infinite steps(1);
-webkit-animation-timing-function:liner;
}
#-webkit-keyframes spin {
from{
-webkit-transform: rotate(0deg)
}
to{
-webkit-transform: rotate(360deg)
}
}
#-moz-keyframes spin {
from{
-moz-transform: rotate(0deg)
}
to{
-moz-transform: rotate(360deg)
}
}
#-webkit-keyframes blink {
0% {background: #fff}
1% {background: none;}
}
#-moz-keyframes blink {
0% {background: #fff}
1% {background: none;}
}
body{
background: #232323;
}
Related
** why box not rotating but its translating the box . translateX is working but rotate is not working in animation **
<style>
.box{
height: 20px;
width: 20px;
background-color: red;
animation: animate 1s linear infinite alternate;
}
#keyframes animate{
0%{
transform: translateX(100px);
}
100%{
transform: rotate(360deg);
}
}
</style>
<div class="box">
</div>
You need to add both the transform properties in the keyframe, take a look at the snippet below
.box{
height: 20px;
width: 20px;
background-color: red;
animation: animate 1s linear infinite alternate;
}
#keyframes animate{
0%{
transform: translateX(100px) rotate(0deg);
}
100%{
transform: translateX(0) rotate(360deg);
}
}
<div class="box">
</div>
This is because it cannot rotate 360deg at the end of the animation.
Almost anything below 360deg will work. Please provide an illustration or video of the result you are trying to accomplish if this solution is not exactly what you want.
<style>
.box {
height: 20px;
width: 20px;
background-color: red;
animation: animate 1s linear infinite alternate;
}
#keyframes animate {
0% {
transform: translateX(100px);
}
100% {
transform: rotate(180deg);
}
}
</style>
<div class="box"></div>
However if you only want it to spin 360deg and not translateX, you can do it using:
<style>
.box {
height: 20px;
width: 20px;
background-color: red;
animation: animate 1s linear infinite alternate;
}
#keyframes animate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
<div class="box"></div>
I have a spinner that I am using for a long running operation but I cannot get it to spin. I have read the other SO questions related to this but none of them seem to get my scenario working.
I have the following HTML
<div class="ms-BasicSpinner">
<div class="ms-Spinner">
<div class="ms-Spinner-circle ms-Spinner--large"></div>
<div class="ms-Spinner-label">Creating...</div>
</div>
</div>
and CSS
.ms-Spinner > .ms-Spinner-circle.ms-Spinner--large {
width: 28px;
height: 28px;
}
.ms-Spinner > .ms-Spinner-circle {
margin: auto;
box-sizing: border-box;
border-radius: 50%;
width: 100%;
height: 100%;
border: 1.5px solid #c7e0f4;
border-top-color: #0078d7;
-webkit-animation: ms-Spinner-spin 1.3s infinite cubic-bezier(.53, .21, .29, .67);
animation: ms-Spinner-spin 1.3s infinite cubic-bezier(.53, .21, .29, .67);
}
.ms-Spinner > .ms-Spinner-label {
color: #0078d7;
margin-top: 10px;
text-align: center;
}
.ms-BasicSpinner .ms-Spinner {
display: inline-block;
margin: 10px 0;
}
I also have to following JSFiddle https://jsfiddle.net/20ufspze/
What am I missing to get the spinner to spin?
Any help much appreciated
Thanks in advance
You apply the cubic bezier function to a rotation to get the desired effect. Adapting the bottom element here you can rotate the blue part with:
#-webkit-keyframes ms-Spinner-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes ms-Spinner-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
And by rewriting the cubic-bezier part as:
-webkit-animation: ms-Spinner-spin 1.3s infinite cubic-bezier(.53, .21, .29, .67);
animation: ms-Spinner-spin 1.3s infinite cubic-bezier(.53, .21, .29, .67);
Best practice to animate any HTML component is use animation keyframes in CSS.
#keyframes anim {
from {
transform: rotate(0deg);
-webkit-transform: rotate(0deg);
}
to {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
}
}
...
.ms-Spinner > .ms-Spinner-circle {
margin: auto;
box-sizing: border-box;
border-radius: 50%;
width: 100%;
height: 100%;
border: 1.5px solid #c7e0f4;
border-top-color: #0078d7;
animation: anim 1.3s infinite;
}
...
Fiddle Link : https://jsfiddle.net/8Ly697ne/
Looking to build something like this - a spin the wheel - using only HTML and CSS, without Javascript
http://tpstatic.com/_sotc/sites/default/files/1010/source/roulettewheel.html
http://www.dougtesting.net/winwheel
Looking for some references or even to see if it can be done.
This is using the Hover effect of spinning. Since css doesn't have event handlers, you can't add/remove classes. However, you can add hover effects:
div {
height: 100px;
width: 100px;
border-radius: 50%;
background: gray;
margin: 0 auto;
text-align: center;
}
div:hover {
-webkit-animation: spin 0.8s infinite linear;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
Hover to see effect: <div>Spin</div>
If you could use a tiny bit of javascript, you could do something like this:
$('div').click(function(){
$(this).toggleClass("thisIsAdded");
});
div {
height: 100px;
width: 100px;
border-radius: 50%;
background: gray;
margin: 0 auto;
text-align: center;
}
.thisIsAdded {
-webkit-animation: spin 0.8s infinite linear;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click to see:<div>spin</div>
Note:
The script here is purely toggling the class 'thisIsAdded'.
As Justinas pointed out We cant fire css style on click event. You need javascript for that. However you can use CSS animation to achieve the spin effect but only with pseudo-selectors.
below is a sample spin effect using only CSS
<style type="text/css">
.content
{
float:left;cursor:pointer;
}
.content::after
{
content:'>';float:right;margin:0 0 0 10px;
-moz-transition:0.5s all;-webkit-transition:0.5s all;
}
.content:hover::after
{
-moz-transform:rotate(90deg);-webkit-transform:rotate(90deg);
}
</style>
<body>
<div class="content">Sample</div>
</body>
Here you go.. Fiddle
CSS:
.circle {
border-radius: 50%;
position: absolute;
top: 10%;
left: 10%;
width: 120px;
height: 120px;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
background: repeating-linear-gradient(
45deg,
#606dbc,
#606dbc 10px,
#465298 10px,
#465298 20px
);
}
#-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); } }
I tried adding -moz- but it doesnt wave.. it works on chrome but not on mozilla firefox
I don't know whats wrong with it.. and help would be appreciated.. I doesnt animate on mozilla firefox :(
here is the code
<ul class="notes-dance">
<li>♩</li>
<li>♪</li>
<li>♫</li>
<li>♪</li>
<li>♫</li>
<li>♬</li>
<li>♩</li>
<li>♫</li>
<li>♬</li>
<li>♩</li>
</ul>
and the css code :
ul li {
display: block;
float: left;
font-size: 2em;
color: #ccc;
text-shadow: 0 -1px 0 white, 0 1px 0 black;
}
.anim {
-moz-animation: music 1s ease-in-out both infinite;
-webkit-animation: music 1s ease-in-out both infinite;
animation : music 1s ease-in-out both infinite;
}
#-webkit-keyframes music {
0%,100% {
-moz-transform: translate3d(0,-10px,0);
-webkit-transform: translate3d(0,-10px,0);
transform: translate3d(0,-10px,0);
}
50% {
-moz-transform: translate3d(0,10px,0);
-webkit-transform: translate3d(0,10px,0);
transform: translate3d(0,10px,0);
}
}
#-moz-keyframes music {
0%,100% {
transform: translate3d(0,-10px,0);
}
50% {
transform: translate3d(0,10px,0);
}
}
.notes-dance{
left: 30%;
right: 50px;
top: 90%;
position: absolute;
}
Use This One for #-moz-keyframes
#-moz-keyframes music {
0% {-moz-transform: translate3d(0,-10px,0);}
50% {-moz-transform: translate3d(0,10px,0);}
100% {-moz-transform: translate3d(0,-10px,0);}
}
You added #-moz-keyframes with no -moz-transform !! and you added -moz-transform to #-webkit-keyframes
As per http://caniuse.com/#feat=css-animation:
#keyframes not supported in an inline or scoped stylesheet in Firefox (bug 830056)
Are you using it in an inline or scoped way? If so, there's your answer.
Using keyframe animation, the div with an id of "Second" animates slightly before the "first" div starts to. Here is my code shouldn't they move at the same speed by default? any help would be great thanks.
body { background-color: black; color: white;}
#First { width: 200px;
height: 50px;
position: absolute;
top:5px;
color: black;
text-align: center;
background-color: yellow;
-webkit-transform-origin: top;
-webkit-animation: myfirst 1s;
-webkit-transform:rotateX(90deg);
-webkit-animation-iteration-count: infinite;
}
#-webkit-keyframes myfirst
{
0% {-webkit-transform:rotateX(0deg);}
100% {-webkit-transform:rotateX(90deg);}
}
#Second { width: 200px;
height: 50px;
position: absolute;
top:5px;
left:200px;
color: black;
text-align: center;
background-color: green;
-webkit-transform-origin: bottom;
-webkit-animation: mysecond 1s;
-webkit-transform:rotateX(0deg);
-webkit-animation-iteration-count: infinite;
}
#-webkit-keyframes mysecond
{
0% {-webkit-transform:rotateX(90deg);}
100% {-webkit-transform:rotateX(0deg);}
}
and the HTML,
<div id="First">FIRST</div>
<div id="Second">SECOND</div>
Code on jsfiddle: http://jsfiddle.net/x3p64/
Demo
#-webkit-keyframes were different for both
As per requirements
New Demo
#-webkit-keyframes myfirst {
0% {
-webkit-transform: scaleY(0);
}
20% {
-webkit-transform: scaleY(0.2);
}
40% {
-webkit-transform: scaleY(0.4);
}
60% {
-webkit-transform: scaleY(0.6);
}
80% {
-webkit-transform: scaleY(0.8);
}
100% {
-webkit-transform: scaleY(1);
}
}
#-webkit-keyframes mysecond {
0% {
-webkit-transform: scaleY(1);
}
20% {
-webkit-transform: scaleY(0.8);
}
40% {
-webkit-transform: scaleY(0.6);
}
60% {
-webkit-transform: scaleY(0.4);
}
80% {
-webkit-transform: scaleY(0.2);
}
100% {
-webkit-transform: scaleY(0);
}
}
It's not that it is starting before, it just looks like it because of the easing properties. Both animations are starting and stopping at the same time, they just look different. Try using a linear easing on both.
-webkit-animation: mysecond 1s linear;