From this question ("Rotate objects around circle using CSS?"), I copied the following code, but is it possible to insert pictures into the code? I would like to insert pictures into the circles so that one picture orbits another. For example, Earth orbiting the sun.
Earth: https://i.imgur.com/Eo52CF0_d.webp?maxwidth=760&fidelity=grand
Sun: https://media.beam.usnews.com/5a/5e/5a739e244b289049e789d7752975/170531-sun-editorial.jpg
How do I modify the code in such a way as to make the earth orbit the sun instead of the blank circles?
<!DOCTYPE html>
<html>
<head>
<style>
.outCircle {
width: 200px;
height: 200px;
background-color: blue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
}
.counterrotate {
width: 50px;
height: 50px;
-webkit-animation: ccircle 10s infinite linear;
}
.inner {
width: 100px;
height: 100px;
background: blue;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: pink;
display: block;
}
#-webkit-keyframes circle {
from {-webkit-transform: rotateZ(0deg)}
to {-webkit-transform: rotateZ(360deg)}
}
#-webkit-keyframes ccircle {
from {-webkit-transform: rotateZ(360deg)}
to {-webkit-transform: rotateZ(0deg)}
}
</style>
</head>
<body>
<script>
.outCircle {
width: 200px;
height: 200px;
background-color: blue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
}
.counterrotate {
width: 50px;
height: 50px;
-webkit-animation: circle 10s infinite linear;
}
.inner {
width: 100px;
height: 100px;
background: blue;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: blue;
display: block;
}
#-webkit-keyframes circle {
from {
-webkit-transform: rotateZ(0deg)
}
to {
-webkit-transform: rotateZ(360deg)
}
}
#-webkit-keyframes ccircle {
from {
-webkit-transform: rotateZ(360deg)
}
to {
-webkit-transform: rotateZ(0deg)
}
}
</script>
<div class="outCircle">
<div class="rotate">
<div class="counterrotate">
<div class="inner">Hello</div>
</div>
</div>
</div>
</body>
</html>
EDIT:
This is the output when I add the images:
<!DOCTYPE html>
<html>
<head>
<style>
.outCircle {
background-image: url("https://media.beam.usnews.com/5a/5e/5a739e244b289049e789d7752975/170531-sun-editorial.jpg");
width: 200px;
height: 200px;
background-color: blue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
}
.counterrotate {
width: 50px;
height: 50px;
-webkit-animation: ccircle 10s infinite linear;
}
.inner {
width: 100px;
height: 100px;
background: blue;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: pink;
display: block;
background-image: url("https://i.imgur.com/Eo52CF0_d.webp?maxwidth=760&fidelity=grand");
}
#-webkit-keyframes circle {
from {-webkit-transform: rotateZ(0deg)}
to {-webkit-transform: rotateZ(360deg)}
}
#-webkit-keyframes ccircle {
from {-webkit-transform: rotateZ(360deg)}
to {-webkit-transform: rotateZ(0deg)}
}
</style>
</head>
<body>
<script>
.outCircle {
width: 200px;
height: 200px;
background-color: blue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
}
.counterrotate {
width: 50px;
height: 50px;
-webkit-animation: circle 10s infinite linear;
}
.inner {
width: 100px;
height: 100px;
background: blue;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: blue;
display: block;
}
#-webkit-keyframes circle {
from {
-webkit-transform: rotateZ(0deg)
}
to {
-webkit-transform: rotateZ(360deg)
}
}
#-webkit-keyframes ccircle {
from {
-webkit-transform: rotateZ(360deg)
}
to {
-webkit-transform: rotateZ(0deg)
}
}
</script>
<div class="outCircle">
<div class="rotate">
<div class="counterrotate">
<div class="inner">Hello</div>
</div>
</div>
</div>
</body>
</html>
i just add background-image css to both element. And linking the earth and moon picture from Wikipedia to that element.
body{
background:#000;
}
.earth, .moon{
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: 120%; /* Resize the background image to cover the entire container */
-moz-border-radius: 50%; /* to make circle shape */
-webkit-border-radius: 50%;
border-radius: 50%;
}
.earth {
background-color: blue;
background-image:url( "https://upload.wikimedia.org/wikipedia/commons/9/90/Small_Earth.jpg" );
position: absolute;
width: 200px;
height: 200px;
box-shadow:0 0 20px dodgerblue;
margin:50px;
}
.moon {
position: relative;
background-color: white;
background-image:url( "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/631px-FullMoon2010.jpg" );
width: 100px;
height: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
}
.counterrotate {
width: 50%;
height: 50%;
-webkit-animation: ccircle 10s infinite linear;
}
#-webkit-keyframes circle {
from {-webkit-transform: rotateZ(0deg)}
to {-webkit-transform: rotateZ(360deg)}
}
#-webkit-keyframes ccircle {
from {-webkit-transform: rotateZ(360deg)}
to {-webkit-transform: rotateZ(0deg)}
}
<div class="earth">
<div class="rotate">
<div class="counterrotate">
<div class="moon"></div>
</div>
</div>
</div>
You could try adding each image as a background-image right in the CSS rules that define their size/shape.
Add a background image to your elements. Open your inspector and click on the element and it will highlight the elements border-box, identify which element is what and then in your CSS, add a background:url(link to the image) to the selector/element you wish to have an image on.
.outCircle {
width: 200px;
height: 200px;
background-color: blue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation: circle 10s infinite linear;
background: url(https://cdn.pixabay.com/photo/2017/05/12/22/48/mouse-2308339__180.jpg) no-repeat;
border-radius: 50%;
}
.counterrotate {
width: 50px;
height: 50px;
-webkit-animation: circle 10s infinite linear;
}
.inner {
width: 100px;
height: 100px;
background: blue;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
display: block;
background: center url(https://as1.ftcdn.net/jpg/00/31/01/02/220_F_31010244_P6FGF9nfBY1oaGFndhdHhUUIfjHqMoib.jpg) no-repeat white;
background-size: 90%;
}
#-webkit-keyframes circle {
from {
-webkit-transform: rotateZ(0deg)
}
to {
-webkit-transform: rotateZ(360deg)
}
}
#-webkit-keyframes ccircle {
from {
-webkit-transform: rotateZ(360deg)
}
to {
-webkit-transform: rotateZ(0deg)
}
}
<div class="outCircle">
<div class="rotate">
<div class="counterrotate">
<div class="inner">Hello</div>
</div>
</div>
</div>
Related
I have a semi circle on the center of my page, which I want to be able to spin, I'm able to do some part of it by adjusting the width but I want a way to make it spin a complete 360degrees. If possible, I want to be able to accomplish it using only css, however if required I don't mind vanilla js (no Jquery).
body {
background-color: lightblue;
}
#txt {
position: fixed;
left: 50%;
transform: translate(-50%, 0);
top: 40%;
font-size: 30px;
color: white;
}
#spinCircle {
position: fixed;
left: 50%;
top: 15%;
height: 50vh;
width: 50px;
border-radius: 0 150px 150px 0;
border-color: black;
color: black;
border-style: solid;
border-left-style: none;
/*background-color: black;*/
animation: spinning infinite;
animation-duration: 3s;
}
#keyframes spinning {
from {
width: 50px
}
to {
width: 0px;
z-index: -5;
}
}
<div id="txt">Hello</div>
<div id="spinCircle" />
Is this what you want?
body {
background-color: lightblue;
}
#txt {
position: fixed;
left: 50%;
transform: translate(-50%, 0);
top: 40%;
font-size: 30px;
color: white;
}
#spinCircle {
position: fixed;
left: 50%;
top: 15%;
height: 50vh;
width: 50px;
border-radius: 0 150px 150px 0;
border-color: black;
color: black;
border-style: solid;
border-left-style: none;
transform-origin: left;
/*background-color: black;*/
animation: spinning infinite;
animation-duration: 3s;
}
#keyframes spinning {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(180deg);
z-index: -5;
}
}
<div id="txt">Hello</div>
<div id="spinCircle" />
If I understand correctly you want the semicircle to revolve around your "hello" text. If so, you could use the transform: rotateY() style to spin your circle. If you do this, you can add your width to the circle div, as well as set the transform-origin to be the left-side of your element so that you rotate around the left-side of your semi-circle and not the center:
transform-origin: left;
width: 50px;
See example below:
body {
background-color: lightblue;
}
#txt {
position: fixed;
left: 50%;
transform: translate(-50%, 0);
top: 40%;
font-size: 30px;
color: white;
}
#spinCircle {
position: fixed;
left: 50%;
top: 15%;
height: 50vh;
width: 200px;
border-radius: 0 150px 150px 0;
border-color: black;
color: black;
border-style: solid;
border-left-style: none;
animation: spinning linear infinite;
animation-duration: 3s;
transform-origin: left;
width: 50px;
}
#keyframes spinning {
from {
transform: rotateY(0);
}
to {
transform: rotateY(360deg);
}
}
<div id="txt">Hello</div>
<div id="spinCircle" />
I have scoured the web and all the sources that I have stumbled upon havent worked in my case. I need the turkey to jump when i click the red circle. Here is My code. Btw it is in js html and css.
function animate() {
document.getElementById("body").class = "bodyAnim";
document.getElementById("beak").class = "beakAnim";
document.getElementById("eyes").class = "eyesAnim";
document.getElementById("pupils").class = "pupilsAnim";
document.getElementById("tail").class = "tailAnim";
document.getElementById("snood").class = "snoodAnim";
document.getElementById("legRight").class = "legRightAnim";
document.getElementById("legLeft").class = "legLeftAnim";
}
.body {
padding: 30px 30px;
height: 35px;
width: 5px;
border-radius: 50%;
background-color: brown;
position: relative;
top: 0px;
animation-name: turkey;
animation-duration: 1s;
}
.beak {
padding: 1px 1px;
width: 1px;
height: 1px;
border-top: 10px solid transparent;
border-left: 25px solid #ffc800;
border-bottom: 5px solid transparent;
position: relative;
left: 40px;
top: 40px;
animation-name: beak;
animation-duration: 1s;
}
.eyes {
padding: 10px 10px;
width: 10px;
height:10px;
border-radius: 50%;
background-color: white;
position: relative;
top: -80px;
animation-name: eyes;
animation-duration: 1s;
}
.pupils {
padding: 5px 5px;
width: 3px;
height: 3px;
border-radius: 50%;
background-color:black;
position: relative;
top:-100px;
animation-name: pupils;
animation-duration: 1s;
}
.snood {
padding: 5px 5px;
width: 1px;
height: 10px;
background-color: red;
border-radius: 50%;
position: relative;
top: -254px;
right: -38px;
animation-name: snood;
animation-duration: 1s;
}
.legRight {
padding: 10px 1px;
width: 1px;
height: 5px;
background-color: black;
position: relative;
top: -219px;
right: 9px;
transform: rotate(30deg);
animation-name: legRight;
animation-duration: 1s;
}
.legLeft {
padding: 10px 1px;
width: 1px;
height: 5px;
background-color: black;
position: relative;
top: -242px;
left: 3px;
transform: rotate(30deg);
animation-name: legLeft;
animation-duration: 1s;
}
.obstacle {
height: 100px;
width: 10px;
background-color: black;
animation: obstacle 2.2s infinite;
position: relative;
top: -460px;
}
body {
background-color: lightblue;
}
<center>
<br><br><br><br><br><br>
<div class="turkey">
<tr>
<td>
<div class="turkey beak"></div>
</td>
<td>
<div class="turkey body"></div>
</td>
</tr>
<div class="turkey eyes"></div>
<div class="turkey pupils"></div>
<style>
.tail {
width: 20px;
height: 150px;
border-radius: 50%;
background-color: brown;
position: relative;
top: -200px;
right: 59px;
transform: rotate(-30deg);
animation-name: tail;
animation-duration: 1s;
}
</style>
<div class="turkey tail" id="tailId"></div>
<div class="turkey snood"></div>
<div class="turkey legRight"></div>
<div class="turkey legLeft"></div>
</div>
<style>
#keyframes turkey {
0% {
top: 0px;
}
50% {
top: -200px;
}
100% {
top: 0px;
}
}
#keyframes beak {
0% {
top: 40px;
}
50% {
top: -160px;
}
100% {
top: 40px;
}
}
#keyframes eyes {
0% {
top: -80px;
}
50% {
top: -280px;
}
100% {
top: -80px;
}
}
#keyframes pupils {
0% {
top: -100px;
}
50% {
top: -300px;
}
100% {
top: -100px
}
}
#keyframes snood {
0% {
top: -250px;
}
50% {
top: -450px;
}
100% {
top: -250px;
}
}
#keyframes legRight {
0% {
top: -219px;
}
50% {
top: -419px;
}
100% {
top: -219px;
}
}
#keyframes legLeft {
0% {
top: -242px;
}
50% {
top: -442px;
}
100% {
top: -242px;
}
}
#keyframes tail {
0% {
top: -200px;
}
50% {
top: -400px;
}
100% {
top: -200px;
}
}
</style>
<style>
.button {
height: 100px;
width: 100px;
background-color: red;
border-radius: 50%;
position: relative;
top:-210px;
overflow = scroll;
}
</style>
<div class="button" onclick="animate()"><h1>JUMP</h1></div>
<div class="obstacle"></div>
<style>
#keyframes obstacle {
from {
left: 370px;
}
to {
left: -870px;
}
}
</style>
So to restate my question, How do I make the turkey jump on the click. so in more of technical terms how do i activate the keyframes with an onclick.
Finally if My code Looks weird, please tell me. Everyone has been saying, fix your code but I do not know how.
Ok, so I'm not proud of what I've done, but I changed up a couple necessary things (like adding id properties and renaming the function) and then wrapped classList.toggle in a setTimeout and it worked. LOL. Please understand that this is all really a bad way to make a Turkey jump, but for the purposes of your question, I got the code to work.
<html>
<head>
<style>
.body {
padding: 30px 30px;
height: 35px;
width: 5px;
border-radius: 50%;
background-color: brown;
position: relative;
top: 0px;
animation-name: turkey;
animation-duration: 1s;
}
.beak {
padding: 1px 1px;
width: 1px;
height: 1px;
border-top: 10px solid transparent;
border-left: 25px solid #ffc800;
border-bottom: 5px solid transparent;
position: relative;
left: 40px;
top: 40px;
animation-name: beak;
animation-duration: 1s;
}
.eyes {
padding: 10px 10px;
width: 10px;
height:10px;
border-radius: 50%;
background-color: white;
position: relative;
top: -80px;
animation-name: eyes;
animation-duration: 1s;
}
.pupils {
padding: 5px 5px;
width: 3px;
height: 3px;
border-radius: 50%;
background-color:black;
position: relative;
top:-100px;
animation-name: pupils;
animation-duration: 1s;
}
.snood {
padding: 5px 5px;
width: 1px;
height: 10px;
background-color: red;
border-radius: 50%;
position: relative;
top: -254px;
right: -38px;
animation-name: snood;
animation-duration: 1s;
}
.legRight {
padding: 10px 1px;
width: 1px;
height: 5px;
background-color: black;
position: relative;
top: -219px;
right: 9px;
transform: rotate(30deg);
animation-name: legRight;
animation-duration: 1s;
}
.legLeft {
padding: 10px 1px;
width: 1px;
height: 5px;
background-color: black;
position: relative;
top: -242px;
left: 3px;
transform: rotate(30deg);
animation-name: legLeft;
animation-duration: 1s;
}
.obstacle {
height: 100px;
width: 10px;
background-color: black;
animation: obstacle 2.2s infinite;
position: relative;
top: -460px;
}
body {
background-color: lightblue;
}
</style>
</head>
<body>
<center>
<br><br><br><br><br><br>
<div class="turkey">
<div id="beak" class="turkey beak"></div>
<div id="body" class="turkey body"></div>
<div id="eyes" class="turkey eyes"></div>
<div id="pupils" class="turkey pupils"></div>
<style>
.tail {
width: 20px;
height: 150px;
border-radius: 50%;
background-color: brown;
position: relative;
top: -200px;
right: 59px;
transform: rotate(-30deg);
animation-name: tail;
animation-duration: 1s;
}
</style>
<div id="tail" class="turkey tail" id="tailId"></div>
<div id="snood" class="turkey snood"></div>
<div id="legRight" class="turkey legRight"></div>
<div id="legLeft" class="turkey legLeft"></div>
</div>
<style>
#keyframes turkey {
0% {
top: 0px;
}
50% {
top: -200px;
}
100% {
top: 0px;
}
}
#keyframes beak {
0% {
top: 40px;
}
50% {
top: -160px;
}
100% {
top: 40px;
}
}
#keyframes eyes {
0% {
top: -80px;
}
50% {
top: -280px;
}
100% {
top: -80px;
}
}
#keyframes pupils {
0% {
top: -100px;
}
50% {
top: -300px;
}
100% {
top: -100px
}
}
#keyframes snood {
0% {
top: -250px;
}
50% {
top: -450px;
}
100% {
top: -250px;
}
}
#keyframes legRight {
0% {
top: -219px;
}
50% {
top: -419px;
}
100% {
top: -219px;
}
}
#keyframes legLeft {
0% {
top: -242px;
}
50% {
top: -442px;
}
100% {
top: -242px;
}
}
#keyframes tail {
0% {
top: -200px;
}
50% {
top: -400px;
}
100% {
top: -200px;
}
}
</style>
<style>
.button {
height: 100px;
width: 100px;
background-color: red;
border-radius: 50%;
position: relative;
top:-210px;
overflow = scroll;
}
</style>
<div class="button" onclick="jump()">
<h1>JUMP</h1>
</div>
<div class="obstacle"></div>
<style>
#keyframes obstacle {
from {
left: 370px;
}
to {
left: -870px;
}
}
</style>
</center>
<script type="text/javascript">
function jump() {
document.getElementById("body").classList.toggle("body");
document.getElementById("beak").classList.toggle("beak");
document.getElementById("eyes").classList.toggle("eyes");
document.getElementById("pupils").classList.toggle("pupils");
document.getElementById("tail").classList.toggle("tail");
document.getElementById("snood").classList.toggle("snood");
document.getElementById("legRight").classList.toggle("legRight");
document.getElementById("legLeft").classList.toggle("legLeft");
setTimeout(() => {
document.getElementById("body").classList.toggle("body");
document.getElementById("beak").classList.toggle("beak");
document.getElementById("eyes").classList.toggle("eyes");
document.getElementById("pupils").classList.toggle("pupils");
document.getElementById("tail").classList.toggle("tail");
document.getElementById("snood").classList.toggle("snood");
document.getElementById("legRight").classList.toggle("legRight");
document.getElementById("legLeft").classList.toggle("legLeft");
}, 0)
}
</script>
</body>
</html>
I have 4 rings of circles that are white and I want one of them to change blue for 1 second, the next one for one second, and so on, totalling 4 seconds. I was thinking of trying this with just CSS animations but I think I'll need JavaScript.. any ideas on how to achieve this? Thanks!
Example: http://imgur.com/a/h0Wy0
HTML:
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
CSS:
.circle {
border-radius: 50%;
background: transparent;
border: 10px solid white;
width: 300px;
height: 300px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
max-width: 100%;
}
.c2 {
width: 250px;
height: 250px;
border-color: white;
}
.c3 {
width: 200px;
height: 200px;
border-color: white;
}
.c4 {
width: 150px;
height: 150px;
}
Here is the JSFiddle: https://jsfiddle.net/ydb48372/3/
You can do this with just css animations. First create animation of 4s duration that sets border-color to blue for 1s or 25% of time of those 4 seconds and the rest of animation returns border-color to gray or 75% of full animation time. Now you just need to use animation-delay on each circle so that animation on one circle starts after 1s when color from previous circle has changed to gray.
.circles {
position: relative;
min-height: 100vh;
}
.circle {
border-radius: 50%;
border: 10px solid gray;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation-duration: 4s;
animation-name: changeColor;
animation-iteration-count: infinite;
}
.c1 {
height: 300px;
width: 300px;
}
.c2 {
height: 250px;
width: 250px;
animation-delay: 1s;
}
.c3 {
height: 200px;
width: 200px;
animation-delay: 2s;
}
.c4 {
height: 150px;
width: 150px;
animation-delay: 3s;
}
#keyframes changeColor {
0% {
border-color: #1C50A8;
}
24% {
border-color: #1C50A8;
}
25% {
border-color: gray;
}
100% {
border-color: gray;
}
}
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
You can use css3 key frames to achieve what you are looking for. You might have to play with the numbers to get the exact timings you want but it should be achievable.
div {
-webkit-animation: mymove 5s infinite; /* Safari 4.0 - 8.0 */
animation: mymove 5s infinite;
}
/* Safari 4.0 - 8.0 */
#-webkit-keyframes mymove {
0% {border-color: white;}
100% {border-color: blue;}
}
/* Standard syntax */
#keyframes mymove {
0% {border-color: white;}
100% {border-color: blue;}
}
Using animation-delay like a commentator mentions is correct.
.circle {
border-radius: 50%;
background: transparent;
border: 10px solid white;
width: 300px;
height: 300px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
max-width: 100%;
}
.c2 {
width: 250px;
height: 250px;
border-color: white;
}
.c3 {
width: 200px;
height: 200px;
border-color: white;
}
.c4 {
width: 150px;
height: 150px;
}
.c1, .c2, .c3, .c4 {
animation: 400ms change-border-color forwards;
}
.c2 {
animation-delay: 450ms;
}
.c3 {
animation-delay: 900ms;
}
.c4 {
animation-delay: 1350ms;
}
#keyframes change-border-color {
from { border-color: white; }
to { border-color: blue; }
}
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
Refer animation and animation-delay property in css
animation: animate 1s;
animation-delay: 1s;
Fiddle
Here's a solution using a pseudoelement on .circles
I've used keyframes to change the height, width and position.
fiddle
body {
background: grey;
}
.circles {
position: relative;
}
.circles::after {
position: absolute;
content: "";
width: 300px;
height: 300px;
top: 0;
left: 0;
right: 0;
margin: auto;
border: 10px solid blue;
border-radius: 50%;
-webkit-animation: blue 5s infinite;
-moz-animation: blue 5s infinite;
-o-animation: blue 5s infinite;
animation: blue 5s infinite;
}
.circle {
border-radius: 50%;
background: transparent;
border: 10px solid white;
width: 300px;
height: 300px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
max-width: 100%;
}
.c2 {
width: 250px;
height: 250px;
border-color: white;
}
.c3 {
width: 200px;
height: 200px;
border-color: white;
}
.c4 {
width: 150px;
height: 150px;
}
#keyframes blue {
25% {
width: 300px;
height: 300px;
top: 0px;
}
25.001% {
width: 250px;
height: 250px;
top: 25px;
}
50% {
width: 250px;
height: 250px;
top: 25px;
}
50.001% {
width: 200px;
height: 200px;
top: 50px;
}
75% {
width: 200px;
height: 200px;
top: 50px;
}
75.001% {
width: 150px;
height: 150px;
top: 75px;
}
100% {
width: 150px;
height: 150px;
top: 75px;
}
}
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
Is there a way to make a div spin, aswell as its content, but make the content not go upside-down while rotating ?
What I mean is that the div-childs would follow the rotation of the mother-div spinning, but while remaining in the same direction (top on top, bottom on bottom).
My english isn't goog enough to articulate properly what I want to do, so here is an exemple :
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
animation: spin 10s infinite linear;
}
#div1 {
border: 1px solid blue;
width: 50px;
height: 50px;
}
#div2 {
border: 1px solid red;
width: 50px;
height: 50px;
position: absolute;
top: 0;
right: 0;
}
#div3 {
border: 1px solid black;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
border: 1px solid green;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover {
animation-play-state: paused;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
<div class="spin">
<div id="div1">hello
</div>
<div id="div2">hello
</div>
<div id="div3">hello
</div>
<div id="div4">hello
</div>
</div>
In the exemple above, the child divs are following the rotation and the spin.
I would like them not to "spin upside-down" and just follow the rotation.
I've seen these type of animation in several websites but I can't recall where exactly.
Is there a way to do this in css/js/jquery/php... ?
You can apply the same animation to the four children, but in reverse. That way, the rotation of the children counteract the rotation of the parent and the children remain upright.
For clarity, I've used animation-direction to reverse the animation:
animation-direction: reverse;
But you could include the direction in your animation shorthand, like:
animation: spin 10s reverse infinite linear;
Here's an example:
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
animation: spin 10s infinite linear;
}
.spin div {
width: 50px;
height: 50px;
animation: spin 10s infinite linear;
animation-direction: reverse;
}
#div1 {
border: 1px solid blue;
}
#div2 {
border: 1px solid red;
position: absolute;
top: 0;
right: 0;
}
#div3 {
border: 1px solid black;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
border: 1px solid green;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover,
.spin:hover div {
animation-play-state: paused;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
<div class="spin">
<div id="div1">hello</div>
<div id="div2">hello</div>
<div id="div3">hello</div>
<div id="div4">hello</div>
</div>
Following #showdev answer, if you want the borders around the inner divs to follow the spin of the outer block and only make the text inside to stay "fixed" in position - you can use a bit of jQuery for that:
$('.spin div').each(function() {
$(this).contents().wrap('<span></span>');
});
I also added a bit of css, you can check inside the snippet:
$('.spin div').each(function() {
$(this).contents().wrap('<span></span>');
});
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
animation: spin 10s infinite linear;
}
.spin div {
text-align: center;
line-height: 50px;
}
.spin div span {
animation: spin 10s infinite linear;
animation-direction:reverse;
display: inline-block;
}
#div1 {
border: 1px solid blue;
width: 50px;
height: 50px;
}
#div2 {
border: 1px solid red;
width: 50px;
height: 50px;
position: absolute;
top: 0;
right: 0;
}
#div3 {
border: 1px solid black;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
border: 1px solid green;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover, .spin:hover span {
animation-play-state: paused;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="spin">
<div id="div1">hello</div>
<div id="div2">hello</div>
<div id="div3">hello</div>
<div id="div4">hello</div>
</div>
I understood you also wanted each of 4 elements to stay in the area of their corners. This might need some extra animation to have them run around the parent edges.
Below the idea of what i understood:
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
position: relative;
animation: spin 10s infinite linear;
}
.spin div {
width: 50px;
height: 50px;
}
#div1 {
border: 1px solid blue;
animation: spin1 10s infinite linear;
position: absolute;
top: 0;
left: 0;
}
#div2 {
animation: spin2 10s infinite linear;
border: 1px solid red;
position: absolute;
top: 0;
right: 0;
}
#div3 {
animation: spin3 10s infinite linear;
border: 1px solid black;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
animation: spin4 10s infinite linear;
border: 1px solid green;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover,
.spin:hover div {
animation-play-state: paused!important;/* or used id and several selectors to avoid the important and overide div#div1 {...}*/
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
#keyframes spin1 {
0% {
transform: rotate(0deg);
}
25% {
top: 150px;
left: 0
}
50% {
left: 150px;
top: 150px
}
75% {
left: 150px;
top: 0;
}
100% {
transform: rotate(-359deg);
}
}
#keyframes spin2 {
0% {
transform: rotate(0deg);
}
25% {
top: 0;
right: 150px
}
50% {
right: 150px;
top: 150px
}
75% {
top: 150px;
right: 0;
}
100% {
transform: rotate(-359deg);
}
}
#keyframes spin3 {
0% {
transform: rotate(0deg);
}
25% {
bottom: 0;
left: 150px
}
50% {
left: 150px;
bottom: 150px
}
75% {
bottom: 150px;
left: 0;
}
100% {
transform: rotate(-359deg);
}
}
#keyframes spin4 {
0% {
transform: rotate(0deg);
}
25% {
right: 0;
bottom: 150px
}
50% {
right: 150px;
bottom: 150px
}
75% {
right: 150px;
bottom: 0;
}
100% {
transform: rotate(-359deg);
}
}
<div class="spin">
<div id="div1">top left</div>
<div id="div2">top right</div>
<div id="div3">bottom left</div>
<div id="div4">bottom right</div>
</div>
Add this rule to each numbered div:
counterspin 10s infinite linear;
and then this keyframes animation
#keyframes counterspin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(-359deg);
}
}
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
animation: spin 10s infinite linear;
position:relative;
}
.spin div {
margin:10px;
animation: spin 10s infinite ease-in-out;
animation-direction: reverse;
}
#div1 {
border: 1px solid blue;
width: 50px;
height: 50px;
position:absolute;
top:0;
left:0;
}
#div2 {
border: 1px solid red;
width: 50px;
height: 50px;
position: absolute;
top: 0;
right: 0;
}
#div3 {
border: 1px solid black;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
border: 1px solid green;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover {
animation-play-state: paused;
}
.spin:hover div {
animation-play-state: paused;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
<div class="spin">
<div id="div1">hello
</div>
<div id="div2">hello
</div>
<div id="div3">hello
</div>
<div id="div4">hello
</div>
</div>
you may try this
.spin {
margin: 50px;
width: 200px;
height: 200px;
background: orange;
animation: spin 10s infinite linear;
position:relative;
}
.spin div {
margin:10px;
animation: spin 10s infinite ease-in-out;
animation-direction: reverse;
}
#div1 {
border: 1px solid blue;
width: 50px;
height: 50px;
position:absolute;
top:0;
left:0;
}
#div2 {
border: 1px solid red;
width: 50px;
height: 50px;
position: absolute;
top: 0;
right: 0;
}
#div3 {
border: 1px solid black;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
}
#div4 {
border: 1px solid green;
width: 50px;
height: 50px;
position: absolute;
bottom: 0;
right: 0;
}
.spin:hover {
animation-play-state: paused;
}
.spin:hover div {
animation-play-state: paused;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
I'm trying create a simple animation that when a user hovers over an element, another element contained within it fills its parent. Currently, I have a JSFiddle that does just that.
BUT, I want to finish this with a few other features that I'm not sure I can actually do in CSS3.
I'm trying to find a way to, upon having the inner circle COMPLETELY fill its parent, (ie when its width/height = 300px), I'd like the fill to pause and not disappear after the animation is complete.
When a user moves their mouse outside the :hover range, I would like the animation to reverse direction as opposed to abruptly stopping.
I've gotten this far with CSS3 but am not sure I can implement these 2 features without resorting to Javascript. Does anyone know of a way of doing this entirely in CSS3/does anyone know if it is possible to do these last two features in CSS3, because I can't seem to find anything.
.circle {
width: 300px;
height: 300px;
background-color: white;
border: 1px solid #000000;
overflow: hidden;
border-radius: 150px;
-moz-border-radius: 150px;
-webkit-border-radius: 150px;
}
.filler {
width: 0px;
height: 0px;
background-color: red;
border: none;
position: relative;
left: 50%;
top: 50%;
border-radius: 150px;
-mox-border-radius: 150px;
-webkit-border-radius: 150px;
animation: empty 1s;
}
.circle:hover .filler {
animation: fill 2s;
-moz-animation: fill 2s;
-webkit-animation: fill 2s;
background-color: blue;
}
#keyframes fill
{
from {background: red; height: 0px; width: 0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}
#-moz-keyframes fill /* Firefox */
{
from {background: red; height: 0px; width: 0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}
#-webkit-keyframes fill /* Safari and Chrome */
{
from {background: red; height:0px; width:0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}
#keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}
#-moz-keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}
#-webkit-keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}
JS Fiddle
You don't need keyframes for this simple animation. Here is CSS you need:
.circle {
position: relative;
width: 300px;
height: 300px;
background-color: white;
border: 1px solid #000000;
border-radius: 150px;
overflow: hidden;
}
.filter {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
background-color: red;
border-radius: 0px;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
.circle:hover .filter {
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 150px;
background-color: blue;
}
and HTML:
<div class="circle">
<div class="filter"></div>
</div>
Here is an example: http://jsbin.com/agekef/1/edit
I hope you can try out for this link might help you out
<http://jsfiddle.net/spacebeers/sELKu/3/>
<http://jsfiddle.net/SZqkb/1/>
<http://css-tricks.com/examples/DifferentTransitionsOnOff/>
Thanks