CSS Animated Circles - Stop center content from rotating
one method would be to break the nesting apart and stack the elements, and then position them accordingly.
I positioned each of the items as needed within the position:absolute;
settings adn then broke out the divs from the nesting:
HTML
<div id="container">
<div id="main">
<div id="outer-circle"></div>
<div id="inner-circle"></div>
<div id="center-circle"></div>
<div id="content">
↓
</div>
</div>
RELEVANT CSS:
#content {
position:absolute;
top: 220px;
left: 350px;
}
#center-circle {
position:absolute;
top:190px;
left: 320px;
}
#inner-circle {
position:absolute;
left: 300px;
top: 170px;
}
DEMO
Problem with stopping rotating items around a circle with CSS and jQuery on mouse hover
Pause the animation of the .item
element whenever you hover over the container with the following selector:
#container:hover .item
This selects all .item
elements when the #container
is hovered upon.
var radius = 100; // adjust to move out items in and out
var fields = $('.item'),
container = $('#container'),
width = container.width(),
height = container.height();
var angle = 0,
step = (2 * Math.PI) / fields.length;
fields.each(function() {
var x = Math.round(width / 2 + radius * Math.cos(angle) - $(this).width() / 2);
var y = Math.round(height / 2 + radius * Math.sin(angle) - $(this).height() / 2);
$(this).css({
left: x + 'px',
top: y + 'px'
});
angle += step;
});
body {
padding: 2em;
}
#container {
width: 200px;
height: 200px;
margin: 10px auto;
border: 1px solid #000;
position: relative;
border-radius: 50%;
animation: spin 20s linear infinite;
}
.item {
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
border-radius: 50%;
position: absolute;
background: #f00;
animation: spin 20s linear infinite reverse;
}
.item:nth-child(1):hover {
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
}
@keyframes spin {
100% {
transform: rotate(1turn);
}
}
#container:hover,
#container:hover .item {
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
animation-play-state: paused;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item"><a href="www.colorchalk.com">4</a></div>
</div>
CSS - Image shifts away from center after rotation transformation
So the issue in this case is that when the animation is applied to the element, it uses the transform: rotate(Xdeg);
to rotate the element. This wouldn't be an issue had the centering not also been done using the transform: translate(-50%, -50%);
property. This issue is demonstrated in this post as an example.
In order to fix this issue, we have to either:
- Change the rotate in the animation to also include our
transform: translate(-50%, -50%);
. This would end up beingtranslate(-50%, -50%) rotate(Xdeg);
- Change the way that centering is handled on the page.
Considering the first option is pretty straightforward, I'm just going to give an example of the second option. This example uses flex
to center the items on the page. This is done using the strategy found here.
.example-container {
display: flex;
align-items: center;
justify-content: center;
}
I've also changed most of the classes and structure just for simplicity purposes and to demonstrate my solution.
*,*::before,*::after { margin: 0; padding: 0; box-sizing: inherit;}
html { font-size: 62.5%;}
body { box-sizing: border-box; padding: 0; background-color: #343233;}
@keyframes rotating { from { transform: rotate(0deg); } to { transform: rotate(360deg); }}
body { font-family: "Lato", sans-serif; font-weight: 400; /*font-size: 16px;*/ line-height: 1.7;}
.full-page { height: 100vh; width: 100vw;}
.flex-container { display: flex; align-items: center; justify-content: center;}
.wrapper { width: 366px; height: 366px; display: flex; align-items: center; justify-content: center;}
.wrapper .logo { position: absolute;}
.wrapper .logo .wordmark,.wrapper .logo .icon { display: block; margin-bottom: 10px;}
.wrapper .circles { width: 100%; height: 100%; margin: auto; position: relative;}
.wrapper .circles .circle { position: absolute; animation-name: rotating; animation-iteration-count: infinite; animation-timing-function: linear;}
.wrapper .circles .circle:nth-child(1) { animation-duration: 20s;}
.wrapper .circles .circle:nth-child(2) { animation-duration: 18s;}
.wrapper .circles .circle:nth-child(3) { animation-duration: 31s;}
.wrapper .circles .circle:nth-child(4) { animation-duration: 33s;}
.wrapper .circles .circle:nth-child(5) { animation-duration: 33s;}
.wrapper .circles .circle:nth-child(6) { animation-duration: 34s;}
.wrapper .circles .circle:nth-child(7) { animation-duration: 45s;}
.wrapper .circles .circle:nth-child(8) { animation-duration: 40s;}
.wrapper .circles .circle:nth-child(9) { animation-duration: 44s;}
.wrapper .circles .circle:nth-child(10) { animation-duration: 46s;}
<section class="full-page flex-container"> <div class="wrapper flex-container"> <div class="logo"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-atom-wordmark-65fad016a61e71c82c2cdd18d94e911f.svg" alt="logo" class="wordmark"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-logo-9fb707770c2c8a018b7a2933906c3436.svg" alt="atom" class="icon"> </div> <div class="circles"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-red-semi-085b4e44d49b2ffe935cc1b2b3094ce8.svg" alt="c1" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-red-be5d1b8a52c13bf286560aba3e4c8c30.svg" alt="c2" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-orange-semi-d2010f0f8e41e03dbf2b5c52166abe4b.svg" alt="c3" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-orange-b3bddfb758b91d22f43d0e14ed8e29da.svg" alt="c4" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-yellow-semi-545681fe77ff01659d472bd379a9f38b.svg" alt="c5" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-yellow-ff207a58ad4f450ea9ac0e17224b39f1.svg" alt="c6" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-green-semi-2d5bc571ee90e710d93f7ae7ddd06e85.svg" alt="c7" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-green-6ab85a1e7343a232273868031b242806.svg" alt="c8" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-blue-semi-7333f1323549be50644411b691b173dd.svg" alt="c9" class="circle"> <img src="https://github-atom-io-herokuapp-com.global.ssl.fastly.net/assets/index-portal-blue-92fc2c151190795bd0147c03d4fb8352.svg" alt="c10" class="circle"> </div> </div></section>
Rotate objects around circle using CSS?
Jquery solution which works for any number of outer items.
Jquery shamelessly stolen from ThiefMaster♦ and their answer at this Q & A
var radius = 100; // adjust to move out items in and out var fields = $('.item'), container = $('#container'), width = container.width(), height = container.height();var angle = 0, step = (2 * Math.PI) / fields.length;fields.each(function() { var x = Math.round(width / 2 + radius * Math.cos(angle) - $(this).width() / 2); var y = Math.round(height / 2 + radius * Math.sin(angle) - $(this).height() / 2); if (window.console) { console.log($(this).text(), x, y); } $(this).css({ left: x + 'px', top: y + 'px' }); angle += step;});
body { padding: 2em;}#container { width: 200px; height: 200px; margin: 10px auto; border: 1px solid #000; position: relative; border-radius: 50%; animation: spin 10s linear infinite;}.item { width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 50%; position: absolute; background: #f00; animation: spin 10s linear infinite reverse;}@keyframes spin { 100% { transform: rotate(1turn); }}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> <div class="item">5</div> <div class="item">6</div></div>
CSS rotate animation of HTML circle text, transform-origin doesn't work
Giving height to the parent of your absolute positioned children, this what you are looking for?
.rotText{
min-width: 80vw;
margin: 5vh auto;
text-align: center;
position: relative;
}
#test{
font-weight: 900;
color: #394add;
font-size: 20px;
display: inline-block;
margin-bottom: 128px;
position: relative;
z-index: 10;
transform: scale(1);
transform-origin: center center;
animation: rotation 5s linear infinite;
height: calc(330px + 2rem);.
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
<div class="rotText">
<img src="05-img/Thinking man.png" alt="Sample Image">
<div class="curved-text" id="test">
<p style="height:165px; position:absolute; transform:rotate(0deg);
transform-origin:0 100%">c</p><p style="height:165px; position:absolute; transform:rotate(8.78048780487805deg);
transform-origin:0 100%">o</p><p style="height:165px; position:absolute; transform:rotate(17.5609756097561deg);
transform-origin:0 100%">l</p><p style="height:165px; position:absolute; transform:rotate(26.34146341463415deg);
transform-origin:0 100%">l</p><p style="height:165px; position:absolute; transform:rotate(35.1219512195122deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(43.90243902439025deg);
transform-origin:0 100%">g</p><p style="height:165px; position:absolute; transform:rotate(52.6829268292683deg);
transform-origin:0 100%">a</p><p style="height:165px; position:absolute; transform:rotate(61.463414634146346deg);
transform-origin:0 100%">r</p><p style="height:165px; position:absolute; transform:rotate(70.2439024390244deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(79.02439024390245deg);
transform-origin:0 100%"> </p><p style="height:165px; position:absolute; transform:rotate(87.8048780487805deg);
transform-origin:0 100%">i</p><p style="height:165px; position:absolute; transform:rotate(96.58536585365854deg);
transform-origin:0 100%">l</p><p style="height:165px; position:absolute; transform:rotate(105.3658536585366deg);
transform-origin:0 100%"> </p><p style="height:165px; position:absolute; transform:rotate(114.14634146341464deg);
transform-origin:0 100%">c</p><p style="height:165px; position:absolute; transform:rotate(122.92682926829269deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(131.70731707317074deg);
transform-origin:0 100%">r</p><p style="height:165px; position:absolute; transform:rotate(140.4878048780488deg);
transform-origin:0 100%">v</p><p style="height:165px; position:absolute; transform:rotate(149.26829268292684deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(158.0487804878049deg);
transform-origin:0 100%">l</p><p style="height:165px; position:absolute; transform:rotate(166.82926829268294deg);
transform-origin:0 100%">l</p><p style="height:165px; position:absolute; transform:rotate(175.609756097561deg);
transform-origin:0 100%">o</p><p style="height:165px; position:absolute; transform:rotate(184.39024390243904deg);
transform-origin:0 100%"> </p><p style="height:165px; position:absolute; transform:rotate(193.1707317073171deg);
transform-origin:0 100%">p</p><p style="height:165px; position:absolute; transform:rotate(201.95121951219514deg);
transform-origin:0 100%">r</p><p style="height:165px; position:absolute; transform:rotate(210.7317073170732deg);
transform-origin:0 100%">i</p><p style="height:165px; position:absolute; transform:rotate(219.51219512195124deg);
transform-origin:0 100%">m</p><p style="height:165px; position:absolute; transform:rotate(228.2926829268293deg);
transform-origin:0 100%">a</p><p style="height:165px; position:absolute; transform:rotate(237.07317073170734deg);
transform-origin:0 100%"> </p><p style="height:165px; position:absolute; transform:rotate(245.85365853658539deg);
transform-origin:0 100%">d</p><p style="height:165px; position:absolute; transform:rotate(254.63414634146343deg);
transform-origin:0 100%">i</p><p style="height:165px; position:absolute; transform:rotate(263.4146341463415deg);
transform-origin:0 100%"> </p><p style="height:165px; position:absolute; transform:rotate(272.19512195121956deg);
transform-origin:0 100%">p</p><p style="height:165px; position:absolute; transform:rotate(280.9756097560976deg);
transform-origin:0 100%">r</p><p style="height:165px; position:absolute; transform:rotate(289.7560975609756deg);
transform-origin:0 100%">o</p><p style="height:165px; position:absolute; transform:rotate(298.5365853658536deg);
transform-origin:0 100%">c</p><p style="height:165px; position:absolute; transform:rotate(307.31707317073165deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(316.09756097560967deg);
transform-origin:0 100%">d</p><p style="height:165px; position:absolute; transform:rotate(324.8780487804877deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(333.6585365853657deg);
transform-origin:0 100%">r</p><p style="height:165px; position:absolute; transform:rotate(342.43902439024373deg);
transform-origin:0 100%">e</p><p style="height:165px; position:absolute; transform:rotate(351.21951219512175deg);
transform-origin:0 100%"></p>
</div>
</div>
On hover stop animation at their respective position
You can pause animation using JQUERY as well as CSS.
A very simple solution to use animation-play-state property.
Try these lines:
.innercircle1 {
animation: inner-circle 5s linear infinite;
animation-play-state: play;
}
.innercircle1:hover{
animation-play-state: paused;
}
CSS offset-path move along arc without rotating
Fixed it by replacing "after" with element with svg background. Added animation to swing back.
Using translate to flip the element and also tuck it under the main circle.
Inspiration on using translate by @laaouatni-anas
$(".kolecko").on('click', function (){
const data = $(this).data('for');
if($(this).hasClass('active')){
$(this).removeClass('active');
$('.kolecko').not(this).removeClass('non-active');
$(this).addClass('wasActive')
.delay(1000)
.queue(function(next){
$(this).removeClass('wasActive');
next();
});
}
else if($(this).hasClass('non-active')){
$('.kolecko').not(this)
.removeClass('active')
.addClass('non-active wasActive')
.delay(1000)
.queue(function(next){
$(this).removeClass('wasActive');
next();
});
$(this).removeClass('non-active').addClass('active');
}
else{
$('.kolecko').not(this).addClass('non-active');
$(this).addClass('active');
}
});
.kolecko{
width: 150px;
height: 150px;
border-radius: 50%;
background: #001f49;
color: white;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
text-align: center;
position: relative;
cursor: pointer;
}
.kolecko.active .ucho{
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1175 1175'%3E%3Cpath style='fill:%23ed174a' class='fil0' d='M957 1l-957 -1c65,184 101,381 101,587 0,206 -36,404 -101,587l957 1c120,0 218,-98 218,-218l0 -738c0,-120 -98,-218 -218,-218z'/%3E%3C/svg%3E");
offset-path: path('M-75,-75 A75,75 0 0,1 -75,75');
animation: move 1000ms ease-in-out forwards;
transform: rotate(-90deg) translate(calc(50% - 4px),0);
}
.kolecko.active .ucho::after{
content: "\f137";
}
.kolecko.wasActive .ucho{
offset-path: path('M-75,-75 A75,75 0 0,1 -75,75');
animation: moveback 1000ms ease-in-out forwards;
transform: rotate(-90deg) translate(calc(50% - 4px),0);
}
.ucho{
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1175 1175'%3E%3Cpath style='fill: %239BA1C6' class='fil0' d='M957 1l-957 -1c65,184 101,381 101,587 0,206 -36,404 -101,587l957 1c120,0 218,-98 218,-218l0 -738c0,-120 -98,-218 -218,-218z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
width: 45px;
height: 45px;
background-size: 100% 100%;
line-height: 45px;
position: absolute;
left: 100%;
top: 50%;
transform: translate(-4px,-50%);
cursor: pointer;
}
.ucho::after{
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f138";
font-size:25px;
}
@keyframes move {
0% {
offset-distance: 50%;
}
100% {
offset-distance: 100%;
}
}
@keyframes moveback {
0% {
offset-distance: 100%;
}
100% {
offset-distance: 50%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
integrity="sha384-
B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
crossorigin="anonymous">
<div class="kolecko" data-for="zalozit-klic">
<span class="chci">chci</span>
<span class="nazev-sluzby">ZALOŽIT s.r.o. NA KLÍČ</span>
<span class="ucho">
</div>
Related Topics
How to Allow Flex-Items to Grow While Keeping the Same Size
Box-Shadow Only on Left and Right
Using Conditional Comments in HTML
Set the Width of Children to Fill the Parent
CSS Opacity Affecting Sibling Image Opacity
Position Floated Elements Directly Under Each Other
Inside Transparent Arrow on the Left
Jquery UI Tooltip Custom Class on Page Load
How to Change the Font Size of the List (Not the Initial View)
Less CSS - Accessing Classes Further Up the Dom Tree from Within a Nested Class
Bootstrap 4 Center Navbar Brand with Collapse
IE7 Absolute Element Appearing Behind Relative One
Clear Fix and Uncollapse Margins with CSS Without Side Effects
Transform-Origin Not Working in Firefox Even Properties in Percentage Value
Css3 Filter: Drop-Shadow Spread Property Alternatives
How to Use Pseudo-Elements (:After, :Before) Inside a Table Row