I am new to CSS and still don't get a lot of stuff! Using only CSS animations I have to create a spinning animation over a roulette.I have to create a sphere and as a background use a roulette img. My question is how can I change the position of the sphere every 10% of the animation, so it can make a full circle around the roulette.
This is the img I am using as a background: http://www.casinoanswers.com/wp-content/uploads/2010/03/american-roulette-wheel.gif
HTML:
<div id="roulette">
<figure class="circle"></figure>
</div>
CSS:
#roulette{
background-image: url("american-roulette-wheel.gif");
width:395px;
height:400px;
margin:0;
}
.circle {
position:fixed;
top:84px;
left:190px;
border-radius: 50%;
height: 30px;
width: 30px;
margin:0;
background: radial-gradient(circle at 10px 10px, #5cabff, #000);
}
Thank you!
By placing your ball/circle image inside a container div and rotating that div, you can create the illusion of the ball traveling around the background. You will have to play with positioning to get it exact, and it might be cool to rotate the ball as well as the container div.
<div id="roulette">
<div class="circleContainer">
<figure class="circle"></figure>
</div>
</div>
#roulette{
background-image: url(http://www.casinoanswers.com/wp-content/uploads/2010/03/american-roulette-wheel.gif);
width:395px;
height:400px;
margin:0;
}
.circle {
border-radius: 50%;
height: 30px;
width: 30px;
margin:0;
background: radial-gradient(circle at 10px 10px, #5cabff, #000);
}
#-webkit-keyframes spinnerRotate
{
from{-webkit-transform:rotate(0deg);}
to{-webkit-transform:rotate(360deg);}
}
#-moz-keyframes spinnerRotate
{
from{-moz-transform:rotate(0deg);}
to{-moz-transform:rotate(360deg);}
}
#-ms-keyframes spinnerRotate
{
from{-ms-transform:rotate(0deg);}
to{-ms-transform:rotate(360deg);}
}
.circleContainer{
height: 250px;
top: 80px;
position: fixed;
left: 190px;
-webkit-animation-name: spinnerRotate;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spinnerRotate;
-moz-animation-duration: 5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spinnerRotate;
-ms-animation-duration: 5s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
https://jsfiddle.net/2gat1m5y/1/
Related
Project Description: I am in quest to apply two animations to a nested images inside a div that actually The Div has the responsibility to move the image up and down because the image is captivated inside it And the image(img) which is nested inside the div, Has the responsibility to rotate successively while the div is bouncing the image up and down.
What I want:
1.the image inside the div should keep rotating 360 degrees
2.While the 1 is happening, The div should keep bouncing or moving up and down
.ground {
position: absolute;
width: 100%;
height: 20px;
background-color: gray;
top: 800px;
}
.ball-container {
position: relative;
width 100px;
height: 100px;
left: 50%;
animation-name: bounce;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-direction: forwards;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#keyframes bounce{
0% {
top: 0px;
}
50% {
top: 700px;
width: 130px;
height: 70px;
}
100% {
top: 0px;
}
}
img {
position: absolute;
width: 100px;
height: 100px;
animation-name: rotation;
animation-direction: forwards;
animation-duration: 1s;
animation-timing-function: linear;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
}
#keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<html>
<div class="ball-container" id="ball-container"><img src="https://image.flaticon.com/icons/svg/53/53283.svg" alt="ball" class="ball" id="ball"/>
</div>
<div class="ground"></div>
</html>
The problem: the bouncing process is awesome, but I dont know how to make the image rotating while it is bouncing.
Thanks.
Codepen Link
THE POST IS EDITED AND HAS NO PROBLEM AFTER APPLYING THE ANSWER
animation-iteration-count should be infinite on img rotation, to match the number of times it bounces as well, else the animation will run once and stop while the box is still bouncing. Also you have a typo, the semicolon in to {transform: rotate(360deg;)} should be outside to {transform: rotate(360deg);}. This is why it doesnt work.
Furthermore animation-direction:forwards is invalid, the correct value is animation-direction:normal.
With these corrections the code is:
.ground {
position: absolute;
width: 100%;
height: 20px;
background-color: gray;
top: 800px;
}
.ball-container {
position: relative;
width 100px;
height: 100px;
left: 50%;
animation-name: bounce;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-direction: normal;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#keyframes bounce{
0% {
top: 0px;
}
50% {
top: 700px;
width: 130px;
height: 70px;
}
100% {
top: 0px;
}
}
img {
position: absolute;
width: 100px;
height: 100px;
animation-name: rotation;
animation-direction: normal;
animation-duration: 1s;
animation-timing-function: linear;
animation-fill-mode: both;
animation-iteration-count: infinite;
}
#keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<html>
<div class="ball-container" id="ball-container"><img src="https://image.flaticon.com/icons/svg/53/53283.svg" alt="ball" class="ball" id="ball"/>
</div>
<div class="ground"></div>
</html>
I'm trying to change a background animation of a div using CSS animations, however, I am not able to make the transition smooth.
Any idea on how to do it? Here is my code.
.cover {
height: 200px;
width: 200px;
background-image: url('https://images.unsplash.com/photo-1582201943021-e8e5cb6dedc2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80');
animation: mymove 5s;
animation-delay: 5s;
animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
}
#keyframes mymove {
from {
background-image: url('https://images.unsplash.com/photo-1582201943021-e8e5cb6dedc2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80');
}
to {
background-image: url('https://images.unsplash.com/photo-1582480356444-60ca00301659?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2001&q=80');
}
<div class="cover">
</div>
What am I doing wrong here?
The normal background change has no animation. What you can do is the following:
You decrease the opacity of the background, change the background image and increase the opacity again. This will achieve a fade effect.
.cover {
height: 200px;
width: 200px;
background-image: url('https://images.unsplash.com/photo-1582201943021-e8e5cb6dedc2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80');
animation: mymove 5s;
animation-delay: 5s;
animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
}
#keyframes mymove {
0% { background-image: url('https://images.unsplash.com/photo-1582201943021-e8e5cb6dedc2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80'); }
50% { background-color:rgba(0, 0, 0, 0.5); }
51% { background-image: url('https://images.unsplash.com/photo-1582480356444-60ca00301659?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2001&q=80'); }
100% { background-color:rgba(0, 0, 0, 1); }
<div class="cover">
</div>
I think the best option is to add a transition to your background image, so if you change it, there will be a animation. (In this example I used the :hover event)
.cover {
height: 200px;
width: 200px;
background-image: url('https://images.unsplash.com/photo-1582201943021-e8e5cb6dedc2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80');
transition: background-image 5s ease-in-out;
}
.cover:hover{
background-image: url('https://images.unsplash.com/photo-1582480356444-60ca00301659?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2001&q=80');
}
<div class="cover">
</div>
I'm playing around with CSS animation, and I was wondering if there's a way to make a vertical line (with certain height) to grow in length automatically and turn to left and add an image at the end when the page loads. I was able to draw vertical line but how to turn it to left and add image.
https://jsfiddle.net/29303g27/3/
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
</div>
By using div inner div
#cool2{
height:0px;
width:1px;
border-bottom:2px solid #000;
-webkit-animation: increase 3s;
-moz-animation: increase 3s;
-o-animation: increase 3s;
animation: increase 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:5s;
-webkit-animation-delay:3s;
}
#keyframes increase {
100% {
width: 200px;
}
}
.image
{
width:0px;
height:200px;
left:2px;
top:2px;
-webkit-animation: fade 3s;
-moz-animation: fade 3s;
-o-animation: fade 3s;
animation: fade 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:6s;
-webkit-animation-delay:6s;
position:absolute;}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
width:200px;
}
}
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
<div id=cool2>
<img class='image' src='https://www.google.co.in/logos/doodles/2017/sitara-devis-97th-birthday-6469056130449408.5-l.png'>
</div>
</div>
and Check this 2nd way using :after Element
#cool:after{
height:0px;
width:1px;
border-bottom:2px solid #000;
-webkit-animation: increase 3s;
-moz-animation: increase 3s;
-o-animation: increase 3s;
animation: increase 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:5s;
-webkit-animation-delay:3s;
position:absolute;
content:'';
}
#keyframes increase {
100% {
width: 200px;
}
}
.image
{
width:0px;
height:200px;
left:2px;
top:2px;
-webkit-animation: fade 3s;
-moz-animation: fade 3s;
-o-animation: fade 3s;
animation: fade 3s;
animation-fill-mode: forwards;
margin-left:10%;
margin-top:0px;
animation-delay:6s;
-webkit-animation-delay:6s;
position:absolute;}
#keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
width:200px;
}
}
#cool
{
width:2px;
margin-left:10%;
background-color:#431;
margin-top:35%;
animation:grow 3s forwards;
position:relative;
}
#keyframes grow
{
0% {
height: 0px;
bottom:0;
}
100%{
height: 200px;
bottom:200px;
}
}
<div id=cool>
<img class='image' src='https://www.google.co.in/logos/doodles/2017/sitara-devis-97th-birthday-6469056130449408.5-l.png'>
</div>
It can be done in many ways. Example
In example I use wrapper element and place line element inside. In this way, line element can use percentage value which relate to wrapper element. It means we don't need to fix height or width just let it grows by image.
<div class='wrapper'>
<img class='image' src='https://images.unsplash.com/photo-1485963631004-f2f00b1d6606?auto=format&fit=crop&w=360&h=180&q=60'>
<div class='line'></div>
</div>
and now animation will be
#keyframes show-up {
0% {
height: 0;
}
50% {
left: 0;
height: 100%;
}
100% {
left: 100%;
height: 100%;
}
}
This question already has an answer here:
CSS Animated Circles - Stop center content from rotating
(1 answer)
Closed 6 years ago.
I'm trying to rotate only the border using css but the font-icon is also rotating. How do I stop the rotation of the icon and make only the border?
CSS:
.circle {
width: 100px;
height: 100px;
background: transparent;
border-radius: 50%;
border: 2px dashed #000;
-webkit-animation-name: Rotate;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: Rotate;
-moz-animation-duration: 2s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: Rotate;
-ms-animation-duration: 2s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
.play {
padding: 20px 30px;
font-size: 56px;
}
#-webkit-keyframes Rotate
{
from{-webkit-transform:rotate(0deg);}
to{-webkit-transform:rotate(360deg);}
}
#-moz-keyframes Rotate
{
from{-moz-transform:rotate(0deg);}
to{-moz-transform:rotate(360deg);}
}
#-ms-keyframes Rotate
{
from{-ms-transform:rotate(0deg);}
to{-ms-transform:rotate(360deg);}
}
HTML:
<div class="circle">
<div class="play"><i class="fa fa-play"></i></div>
</div>
Where am I going wrong with this code?
DEMO JSFIDDEL
rotating parent will rotate child as well so it's better to style border separately like here
.circle {
width: 100px;
height: 100px;
position: relative;
}
.circle .border {
/* content: ''; */
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: transparent;
border-radius: 50%;
border: 2px dashed #000;
-webkit-animation-name: Rotate;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: Rotate;
-moz-animation-duration: 2s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: Rotate;
-ms-animation-duration: 2s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
.play {
padding: 20px 30px;
font-size: 56px;
}
.stop {
font-size: 12px;
padding: 30px;
text-align: center;
}
#-webkit-keyframes Rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#-moz-keyframes Rotate {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}
#-ms-keyframes Rotate {
from {
-ms-transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
}
}
<div class="circle">
<div class="border"></div>
<div class="play"><i class="fa fa-play"></i>
</div>
</div>
<p>
PS: The icon loading is a bit slow. Wait until it shows up.
</p>
<div class="circle">
<div class="border"></div>
<div class="stop">Stop me please</div>
</div>
<div class="button-container">
<i class="fa fa-play button-icon"></i>
<div class="button-border"></div>
</div>
You may find an updated version of your sample here
JSFiddle
I have two images and I've found css ::after keeps one image on top of the other quite nicely, even when the screen size changes. The thing is I want the image underneath to spin and the image on top to remain stationary. I can't seem to do this and I'm not even sure this is possible using ::after. Is there a way to do it?
Here's my code:
.box {
display: inline-block;
position: fixed;
top: 50%;
left: 30%;
-webkit-animation-name: spinnerRotate;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spinnerRotate;
-moz-animation-duration: 5s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spinnerRotate;
-ms-animation-duration: 5s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
}
.box:after {
content: '';
position: absolute;
width: 50px;
height: 50px;
top: 25px;
right: 0;
bottom: 0;
left: 25px;
background: url("../Content/images/top.png");
}
<div class="box">
<img src="../Content/images/bottom.png">
</div>
Here's the animation:
#-webkit-keyframes spinnerRotate
{
from{-webkit-transform:rotate(0deg);}
to{-webkit-transform:rotate(720deg);}
}
#-moz-keyframes spinnerRotate
{
from{-moz-transform:rotate(0deg);}
to{-moz-transform:rotate(720deg);}
}
#-ms-keyframes spinnerRotate
{
from{-ms-transform:rotate(0deg);}
to{-ms-transform:rotate(720deg);}
}
Well, you can do it like this:
#keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.box::after {
animation: rotate 5s infinite;
content:url("http://lorempixel.com/sports/400/200/");
}
<div class="box">
<img src="http://lorempixel.com/g/400/200/">
</div>
I changed your background-image with using the content property. This is not necessary but more comfortable, as you don't need to give the image dimensions.
Here is a nice article about css animations: https://css-tricks.com/almanac/properties/a/animation/
Here is information about compatibility: http://caniuse.com/#search=animation