I found this carousel and wanted to use it. The problem is that the original carousel had many slides (about 8) while I only want 3. It seems like it would be pretty straight-forward, but I just cannot get it to work properly with 3 slides. Instead it finishes the three slides then waits the amount of time it would have taken the extra slides which I removed to scroll through before repeating.
I have tried many things. Removing an element from .vertical_carousel__item:nth-child() does nothing. Doing this then adjusting animation: carousel-animate-vertical 27s linear infinite just causes the carousel to stutter rather than moving smoothly, also changing animation-delay: calc(3s * -1) causes the slides to overlap.
I've tried so many combinations of things but just can't get it to run smoothly and loop after my three slides without having to wait like 15 seconds before they loop again.
Any help would be muchly appreciated.
<div class="vertical_carousel_div">
<div class="vertical_carousel">
<div class="vertical_carousel__item">
<div class="vertical_carousel__item-head">
</div>
<div class="vertical_carousel__item-body">
<p class="vertical_carousel_title">1</p>
</div>
</div>
<div class="vertical_carousel__item">
<div class="vertical_carousel__item-head">
</div>
<div class="vertical_carousel__item-body">
<p class="vertical_carousel_title">2</p>
</div>
</div>
<div class="vertical_carousel__item">
<div class="vertical_carousel__item-head">
</div>
<div class="vertical_carousel__item-body">
<p class="vertical_carousel_title">3</p>
</div>
</div>
</div>
</div>
.vertical_carousel__item {
display: flex;
align-items: center;
position: absolute;
width: 100%;
padding: 0 12px;
opacity: 0;
filter: drop-shadow(0 2px 2px #555);
will-change: transform, opacity;
animation: carousel-animate-vertical 27s linear infinite;
}
.vertical_carousel__item:nth-child(1) {
animation-delay: calc(3s * -1);
}
.vertical_carousel__item:nth-child(2) {
animation-delay: calc(3s * 0);
}
.vertical_carousel__item:nth-child(3) {
animation-delay: calc(3s * 1);
}
.vertical_carousel__item:nth-child(4) {
animation-delay: calc(3s * 2);
}
.vertical_carousel__item:nth-child(5) {
animation-delay: calc(3s * 3);
}
.vertical_carousel__item:nth-child(6) {
animation-delay: calc(3s * 4);
}
.vertical_carousel__item:nth-child(7) {
animation-delay: calc(3s * 5);
}
.vertical_carousel__item:nth-child(8) {
animation-delay: calc(3s * 6);
}
.vertical_carousel__item:last-child {
animation-delay: calc(-3s * 2);
}
Thank you.
You can
Delete the number of HTML elements to 3.
Adjust the timing from 27s to 9s in the animation-duration.
You need to adjust the number of key frame steps according to the elements.
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
font-family: 'Work Sans', sans-serif;
font-weight: 400;
height: 100vh;
}
.wrapper {
background: linear-gradient(60deg, #420285, #08BDBD);
height: 100%;
width: 100%;
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
}
.carousel {
position: relative;
width: 100%;
max-width: 500px;
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
}
.carousel__item {
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
position: absolute;
width: 100%;
padding: 0 12px;
opacity: 0;
-webkit-filter: drop-shadow(0 2px 2px #555);
filter: drop-shadow(0 2px 2px #555);
will-change: transform, opacity;
-webkit-animation: carousel-animate-vertical 9s linear infinite;
animation: carousel-animate-vertical 9s linear infinite;
}
.carousel__item:nth-child(1) {
-webkit-animation-delay: calc(3s * -1);
animation-delay: calc(3s * -1);
}
.carousel__item:nth-child(2) {
-webkit-animation-delay: calc(3s * 0);
animation-delay: calc(3s * 0);
}
.carousel__item:last-child {
-webkit-animation-delay: calc(-3s * 2);
animation-delay: calc(-3s * 2);
}
.carousel__item-head {
border-radius: 50%;
background-color: #d7f7fc;
width: 90px;
height: 90px;
padding: 14px;
position: relative;
margin-right: -45px;
flex-shrink: 0;
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
font-size: 50px;
}
.carousel__item-body {
width: 100%;
background-color: #fff;
border-radius: 8px;
padding: 16px 20px 16px 70px;
}
.title {
text-transform: uppercase;
font-size: 20px;
margin-top: 10px;
}
#keyframes carousel-animate-vertical {
0% {
transform: translateY(100%) scale(0.5);
opacity: 0;
visibility: hidden;
}
9%,
33.3333333333% {
transform: translateY(100%) scale(0.7);
opacity: .4;
visibility: visible;
}
42.3333333333%,
66.6666666667% {
transform: translateY(0) scale(1);
opacity: 1;
visibility: visible;
}
75.6666666667% {
transform: translateY(-100%) scale(0.7);
opacity: .4;
visibility: visible;
}
100% {
transform: translateY(-100%) scale(0.7);
opacity: .075;
visibility: hidden;
}
}
<div class='wrapper'>
<div class='carousel'>
<div class='carousel__item'>
<div class='carousel__item-head'>
🐳
</div>
<div class='carousel__item-body'>
<p class='title'>spouting whale</p>
<p>Unicode: U+1F433</p>
</div>
</div>
<div class='carousel__item'>
<div class='carousel__item-head'>
🐋
</div>
<div class='carousel__item-body'>
<p class='title'>whale</p>
<p>Unicode: U+1F40B</p>
</div>
</div>
<div class='carousel__item'>
<div class='carousel__item-head'>
🐬
</div>
<div class='carousel__item-body'>
<p class='title'>dolphin</p>
<p>Unicode: U+1F42C</p>
</div>
</div>
</div>
</div>
Related
I am trying to add scale up animation on a div.
I tried this using both transition and animation property.
In case of transition you can notice that when hovered out the animation is smoothly reversed. However, this doesn't happen when using animation property (the div transitions back to initial width instantly)
Can someone tell me:
Why this behaviour in case of animation only?
How can I achieve the same using animation property?
.animations {
display: flex;
padding: 80px;
width: 100vw;
height: 100vh;
background: linear-gradient(to right, #f3d2d2, white, #cee5f3);
}
.animations > div {
width: 200px;
height: 200px;
margin: 40px;
font-family: system-ui;
display: flex;
flex-direction: column;
align-items: center;
}
.animations > p {
color: black;
flex: 1;
text-align: center;
}
.animations .animated-box {
flex: 2;
width: 100%;
background: grey;
cursor: pointer;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.animated-box.scale-up {
}
.animated-box.scale-up:hover {
animation: scale-up 0.5s ease forwards;
transform: scale(1);
}
.animated-box.scale-up-with-mouseout {
transition: transform 0.5s ease-in;
}
.animated-box.scale-up-with-mouseout:hover {
transform: scale(1.2);
}
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
<div class="animations">
<div>
<div class="animated-box scale-up">Hover me</div>
<p>Scale up (with keyframes)</p>
</div>
<div>
<div class="animated-box scale-up-with-mouseout">Hover me</div>
<p>Scale up (with transition)</p>
</div>
</div>
invert this part only
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
and to fix the animation when mouse out add a new keyframe
#keyframes scale-down {
0% {transform: scale(1.2)};
100%{transform: scale(1)};
}
and apply it to the class .animated-box.scale-up
.animated-box.scale-up {
animation: scale-down 0.5s ease forwards;
}
.animations {
display: flex;
padding: 80px;
width: 100vw;
height: 100vh;
background: linear-gradient(to right, #f3d2d2, white, #cee5f3);
}
.animations > div {
width: 200px;
height: 200px;
margin: 40px;
font-family: system-ui;
display: flex;
flex-direction: column;
align-items: center;
}
.animations > p {
color: black;
flex: 1;
text-align: center;
}
.animations .animated-box {
flex: 2;
width: 100%;
background: grey;
cursor: pointer;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.animated-box.scale-up {
animation: scale-down 0.5s ease forwards;
}
.animated-box.scale-up:hover {
animation: scale-up 0.5s ease forwards;
}
.animated-box.scale-up-with-mouseout {
transition: transform 0.5s ease-in;
}
.animated-box.scale-up-with-mouseout:hover {
transform: scale(1.2);
}
#keyframes scale-up {
100% {transform: scale(1.2)};
0%{transform: scale(1)};
}
#keyframes scale-down {
0% {transform: scale(1.2)};
100%{transform: scale(1)};
}
<div class="animations">
<div>
<div class="animated-box scale-up">Hover me</div>
<p>Scale up (doesn't work)</p>
</div>
<div>
<div class="animated-box scale-up-with-mouseout">Hover me</div>
<p>Scale up (works)</p>
</div>
</div>
I'm attempting to have three objects rotating around a circle. So far I've been able to get one object to spin around the circle. I am unable to get more than one without messing up the code. Could anyone advise on the best way to accomplish this? Here is part of the code and a Fiddle. Thanks!
Here is the Demo
.outCircle {
width: 200px;
height: 200px;
background-color: lightblue;
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: red;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: red;
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)
}
}
<div class="outCircle">
<div class="rotate">
<div class="counterrotate">
<div class="inner">hello
</div>
</div>
</div>
</div>
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>
How about this, demo at the bottom with 3 circles:
.outCircle {
width: 200px;
height: 200px;
background-color: lightblue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.duringTwentyOne {
-webkit-animation-duration: 21s;
}
.duringTen {
-webkit-animation-duration: 10s;
}
.duringFour {
-webkit-animation-duration: 4s;
}
.infinite {
-webkit-animation-iteration-count: infinite;
}
.linear {
-webkit-animation-timing-function: linear;
}
.counter {
width: 50px;
height: 50px;
-webkit-animation-duration: inherit;
-webkit-animation-direction: reverse;
-webkit-animation-timing-function: inherit;
-webkit-animation-iteration-count: inherit;
-webkit-animation-name: inherit;
}
.rotate {
width: 100%;
height: 100%;
-webkit-animation-name: circle;
position: relative;
z-index : 10;
display : block;
}
.second {
top : -100%;
}
.thirdBigger {
top : -240%;
left: -40%;
width:150%;
height: 150%;
}
.inner {
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 100px;
position: absolute;
left: 0px;
top: 0px;
background-color: red;
display: block;
}
.red {
background: red;
}
.green {
background: green;
}
#keyframes circle {
from {-webkit-transform: rotateZ(0deg)}
to {-webkit-transform: rotateZ(360deg)}
}
<div class="outCircle">
<div class="rotate linear infinite duringTen">
<div class="counter">
<div class="inner">hello
</div>
</div>
</div>
<div class="second rotate linear infinite duringFour">
<div class="counter">
<div class="inner red">bye bye
</div>
</div>
</div>
<div class="thirdBigger rotate linear infinite duringTwentyOne">
<div class="counter">
<div class="inner green">s'up
</div>
</div>
</div>
</div>
Here is a more generic idea with less of code where you don't need JS and you only need to apply an animation to the item (not the container). The trick is to make all the elements at the same position and using the same animation then with the delay we can have the needed result:
#container {
width: 200px;
height: 200px;
margin: 40px auto;
border: 1px solid #000;
display:grid;
grid-template-columns:30px;
grid-template-rows:30px;
place-content: center;
border-radius: 50%;
}
.item {
grid-area:1/1;
line-height: 30px;
text-align: center;
border-radius: 50%;
background: #f00;
animation: spin 12s var(--d,0s) linear infinite; /* duration = 12s, numbor of item = 6 so a delay of 12/6 = 2s */
transform:rotate(0) translate(100px) rotate(0);
}
#keyframes spin {
100% {
transform:rotate(1turn) translate(100px) rotate(-1turn);
}
}
<div id="container">
<div class="item" style="--d:0s">1</div>
<div class="item" style="--d:-2s">2</div>
<div class="item" style="--d:-4s">3</div>
<div class="item" style="--d:-6s">4</div>
<div class="item" style="--d:-8s">5</div>
<div class="item" style="--d:-10s">6</div>
</div>
We can easily scale to any number using some CSS variables:
#container {
--n:7; /* number of item */
--d:12s; /* duration */
width: 200px;
height: 200px;
margin: 40px auto;
border: 1px solid #000;
display:grid;
grid-template-columns:30px;
grid-template-rows:30px;
place-content: center;
border-radius: 50%;
}
.item {
grid-area:1/1;
line-height: 30px;
text-align: center;
border-radius: 50%;
background: #f00;
animation: spin var(--d) linear infinite;
transform:rotate(0) translate(100px) rotate(0);
}
#keyframes spin {
100% {
transform:rotate(1turn) translate(100px) rotate(-1turn);
}
}
.item:nth-child(1) {animation-delay:calc(-0*var(--d)/var(--n))}
.item:nth-child(2) {animation-delay:calc(-1*var(--d)/var(--n))}
.item:nth-child(3) {animation-delay:calc(-2*var(--d)/var(--n))}
.item:nth-child(4) {animation-delay:calc(-3*var(--d)/var(--n))}
.item:nth-child(5) {animation-delay:calc(-4*var(--d)/var(--n))}
.item:nth-child(6) {animation-delay:calc(-5*var(--d)/var(--n))}
.item:nth-child(7) {animation-delay:calc(-6*var(--d)/var(--n))}
.item:nth-child(8) {animation-delay:calc(-7*var(--d)/var(--n))}
.item:nth-child(9) {animation-delay:calc(-8*var(--d)/var(--n))}
/*.item:nth-child(N) {animation-delay:calc(-(N - 1)*var(--d)/var(--n))}*/
<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 class="item">7</div>
</div>
<div id="container" style="--n:5;--d:5s">
<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>
<div id="container" style="--n:9">
<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 class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
Not sure if this is what you are after, but you need to position your rotating circles absolutely (so they don't interfere with each other) and then give them their own animation:
For the counter rotation, just make them then minus of what the rotation degrees is and that will keep your text horizontal
.outCircle {
width: 200px;
height: 200px;
background-color: lightblue;
left: 270px;
position: absolute;
top: 50px;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
border-radius: 100px;
}
.rotate {
width: 100%;
height: 100%;
position: absolute; /* add this */
}
.counterrotate {
width: 100px;
height: 100px;
}
.inner {
width: 100px;
height: 100px;
text-align: center;
vertical-align: middle;
background: red;
border-radius: 100px;
background-color: red;
display: table-cell;
}
.anim1 {
-webkit-animation: circle1 10s infinite linear;
}
.anim1 .counterrotate {
-webkit-animation: ccircle1 10s infinite linear;
}
.anim2 {
-webkit-animation: circle2 10s infinite linear;
}
.anim2 .counterrotate {
-webkit-animation: ccircle2 10s infinite linear;
}
.anim3 {
-webkit-animation: circle3 10s infinite linear;
}
.anim3 .counterrotate {
-webkit-animation: ccircle3 10s infinite linear;
}
#-webkit-keyframes circle1 {
from {
-webkit-transform: rotateZ(0deg)
}
to {
-webkit-transform: rotateZ(360deg)
}
}
#-webkit-keyframes ccircle1 {
from {
-webkit-transform: rotateZ(0deg)
}
to {
-webkit-transform: rotateZ(-360deg)
}
}
#-webkit-keyframes circle2 {
from {
-webkit-transform: rotateZ(90deg)
}
to {
-webkit-transform: rotateZ(450deg)
}
}
#-webkit-keyframes ccircle2 {
from {
-webkit-transform: rotateZ(-90deg)
}
to {
-webkit-transform: rotateZ(-450deg)
}
}
#-webkit-keyframes circle3 {
from {
-webkit-transform: rotateZ(180deg)
}
to {
-webkit-transform: rotateZ(540deg)
}
}
#-webkit-keyframes ccircle3 {
from {
-webkit-transform: rotateZ(-180deg)
}
to {
-webkit-transform: rotateZ(-540deg)
}
}
<div class="outCircle">
<div class="rotate anim1">
<div class="counterrotate">
<div class="inner">hello
</div>
</div>
</div>
<div class="rotate anim2">
<div class="counterrotate">
<div class="inner">hello
</div>
</div>
</div>
<div class="rotate anim3">
<div class="counterrotate">
<div class="inner">hello
</div>
</div>
</div>
</div>
Use translateX.
See this jsfiddle.
I made the outer circle position: relative and the inner ones position: absolute, so they lie on top of each others mids (which is just for illustration, this is just for positioning the child circles on the same spot; grouping them).
Then, from this center spot, the translateX tells the animation to give it a radius of in this case 100px (which is the radius of the outer circle).
There you go.
.circleLink {
color: #ececec;
text-transform: uppercase;
font-size: 24px;
line-height: 120%;
position: relative;
display: inline-block;
border: 1px solid blue;
width: 200px;
height: 200px;
-moz-box-flex: 0;
flex: 0 0 270px;
display: -moz-box;
display: flex;
-moz-box-pack: center;
justify-content: center;
-moz-box-align: center;
align-items: center;
border-radius: 50%;
}
.round>span:first-child {
position: relative;
color:blue;
}
.round>span:first-child::before {
content: "";
position: absolute;
width: 100%;
height: 0;
border: 1px solid #ececec;
bottom: -5px;
background: #ececec;
border-radius: 10px;
left: 0;
}
.round>span:nth-child(2) {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
transform: rotate(90deg);
}
.circleLink>span:nth-child(2) {
position: absolute;
z-index: 1;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.circleLink>span:nth-child(2) span {
position: absolute;
top: -webkit-calc(50% - 0.5px);
top: -moz-calc(50% - .5px);
top: calc(50% - 0.5px);
left: 50%;
z-index: 1;
width: 50%;
height: 1px;
-webkit-transform-origin: left;
-moz-transform-origin: left;
transform-origin: left;
-webkit-animation: linkRotate 5s linear 0s infinite;
-moz-animation: linkRotate 5s linear 0s infinite;
animation: linkRotate 5s linear 0s infinite;
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
animation-play-state: paused;
}
.circleLink>span:nth-child(2) span:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
top: -10px;
right: -10px;
background: #42B4EF;
border-radius: 50%;
}
.circleLink:hover>span:nth-child(2) span {
-webkit-animation-play-state: running;
-moz-animation-play-state: running;
animation-play-state: running;
}
#-webkit-keyframes linkRotate {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-webkit-transform: rotate(1turn);
transform: rotate(1turn)
}
}
#-moz-keyframes linkRotate {
0% {
-moz-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-moz-transform: rotate(1turn);
transform: rotate(1turn)
}
}
#keyframes linkRotate {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-webkit-transform: rotate(1turn);
-moz-transform: rotate(1turn);
transform: rotate(1turn)
}
}
<div class="round">
<a href="#" class="circleLink">
<span>Loram</span>
<span><span></span></span>
</a>
</div>
as a newbie in CSS animations i'm trying to make some spinners,
Unfortunately i am not able to make repeat a cycle of animations and i'm searching help!
Here is the code:
.rotate {
transform: rotate(-45deg);
display: flex;
}
#column {
display: flex;
flex-direction: column;
}
.block3 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: 0s;
}
.block4 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: .4s;
}
.block2 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: .8s;
}
.block1 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s linear both;
animation-delay: 1.2s;
}
#keyframes fade {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="it">
<head>
<style>
body {
position: absolute;
margin: 0;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.margin {
margin-top: 200px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
</style>
</head>
<body>
<section class="animation rotate">
<div id="column">
<div class="block1"></div>
<div class="block2"></div>
</div>
<div id="column">
<div class="block3"></div>
<div class="block4"></div>
</div>
</section>
</body>
</html>
I even tried with infinite attribute but obviously it continues to repeat every block:
.rotate {
transform: rotate(-45deg);
display: flex;
}
#column {
display: flex;
flex-direction: column;
}
.block3 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: 0s;
}
.block4 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: .4s;
}
.block2 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: .8s;
}
.block1 {
width: 45px;
height: 45px;
background-color: black;
margin: 1px;
animation: fade .4s infinite linear both;
animation-delay: 1.2s;
}
#keyframes fade {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="it">
<head>
<style>
body {
position: absolute;
margin: 0;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.margin {
margin-top: 200px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
</style>
</head>
<body>
<section class="animation rotate">
<div id="column">
<div class="block1"></div>
<div class="block2"></div>
</div>
<div id="column">
<div class="block3"></div>
<div class="block4"></div>
</div>
</section>
</body>
</html>
So in conclusion:
block1 executes, block2 executes, block3 executes, block4 executes then repeat from block1
You will need to create a keyframe for each block:
.rotate {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg) ;
display: flex;
flex-wrap: wrap;
width: 100px; /* change this to control the size */
}
.rotate div {
flex:1 1 48%; /* little less than 50% to consider the margin */
margin: 1px;
background-color: black;
animation: 2s linear infinite;
}
/* maintain square ratio*/
.rotate div::before {
content: "";
display: block;
padding-top: 100%;
}
/**/
.rotate div:nth-child(1) { animation-name:fade4}
.rotate div:nth-child(2) { animation-name:fade1}
.rotate div:nth-child(3) { animation-name:fade3}
.rotate div:nth-child(4) { animation-name:fade2}
/* [0% first one 20%][20% second one 40%][40% third one 60%][60% fourth one 80%][80% pause 100%] */
#keyframes fade1 {
0% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
20%,100% {
opacity: 0;
}
}
#keyframes fade2 {
0%,20% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
40%,100% {
opacity: 0;
}
}
#keyframes fade3 {
0%,40% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
60%,100% {
opacity: 0;
}
}
#keyframes fade4 {
0%,60% {
opacity: 1;
transform: perspective(140px) rotateX(-180deg);
}
80%,100% {
opacity: 0;
}
}
<section class="animation rotate">
<div></div>
<div></div>
<div></div>
<div></div>
</section>
So, I have a set of boxes placed around each other. But using CSS animations I want to hide all the boxes One by One at a time, when the last box is hidden, I want to show back all the boxes but in reverse order, where last box appears first and then 9th, 8th and till 1st box appears back. And then again this animation repeats.
* {
box-sizing: border-box;
position: relative;
}
body {
background: #fcc;
}
#keyframes blink {
0% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.boxes {
width: 10%;
height: 50px;
background: tomato;
border: 1px solid #ccc;
animation: blink 10s alternate linear infinite;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
}
.boxes:nth-child(odd) {
background: orange;
top: 40px;
}
.box-1 {
animation-duration: 9s;
animation-delay: 1s
}
.box-2 {
animation-duration: 8s;
animation-delay: 2s
}
.box-3 {
animation-duration: 7s;
animation-delay: 3s
}
.box-4 {
animation-duration: 6s;
animation-delay: 4s
}
.box-5 {
animation-duration: 5s;
animation-delay: 5s
}
.box-6 {
animation-duration: 4s;
animation-delay: 6s
}
.box-7 {
animation-duration: 3s;
animation-delay: 7s
}
.box-8 {
animation-duration: 2s;
animation-delay: 8s
}
.box-9 {
animation-duration: 1s;
animation-delay: 9s
}
<div class="wrapper">
<div class="boxes box-1">1</div>
<div class="boxes box-2">2</div>
<div class="boxes box-3">3</div>
<div class="boxes box-4">4</div>
<div class="boxes box-5">5</div>
<div class="boxes box-6">6</div>
<div class="boxes box-7">7</div>
<div class="boxes box-8">8</div>
<div class="boxes box-9">9</div>
<div>
Here is another idea, with mix-blend-mode and animation in 11 steps .
* {
box-sizing: border-box;
margin:0;
}
html,body {
background: linear-gradient( to bottom left, purple, green, yellow) pink;
min-height: 100vh
}
.wrapper {
display: flex;
position: relative;
background: linear-gradient(to right, black, black) no-repeat;
background-size: 0% 100%;
animation: blink 10s infinite alternate steps(11, end);
mix-blend-mode: lighten;
}
.boxes {
flex-grow: 1;
;
height: 50px;
background: tomato;
border: 1px solid #ccc;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
mix-blend-mode: overlay;
}
.boxes:nth-child(odd) {
background: orange;
margin-top: 40px;
}
#keyframes blink {
100% {
background-size: 110% 100%;
;
}
}
<div class="wrapper">
<div class="boxes">1</div>
<div class="boxes">2</div>
<div class="boxes">3</div>
<div class="boxes">4</div>
<div class="boxes">5</div>
<div class="boxes">6</div>
<div class="boxes">7</div>
<div class="boxes">8</div>
<div class="boxes">9</div>
<div class="boxes">10</div>
</div>
Here is an idea using mask where you don't need to apply an individual animation to each element. You simply animate a gradient from right to left to show hide your elements:
.wrapper {
display:flex;
padding-right:10%;
margin-right:-10%;
-webkit-mask:linear-gradient(to right,transparent 50%,#fff 0) right/200% 100%;
mask:linear-gradient(to right,transparent 50%,#fff 0) right/200% 100%;
animation:hide 3s steps(11) infinite alternate;
}
.boxes {
width: 10%;
height: 50px;
background: tomato;
border: 1px solid #ccc;
box-sizing:border-box;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
}
.boxes:nth-child(odd) {
background: orange;
margin-top: 40px;
}
#keyframes hide {
100% {
-webkit-mask-position:left;
mask-position:left;
}
}
body {
background:grey;
overflow:hidden;
}
<div class="wrapper">
<div class="boxes">1</div>
<div class="boxes">2</div>
<div class="boxes">3</div>
<div class="boxes">4</div>
<div class="boxes">5</div>
<div class="boxes">6</div>
<div class="boxes">7</div>
<div class="boxes">8</div>
<div class="boxes">9</div>
<div class="boxes">10</div>
</div>
And with a fading animation:
.wrapper {
display:flex;
-webkit-mask:linear-gradient(to right,transparent 33%,#fff 66%) right/300% 100%;
mask:linear-gradient(to right,transparent 33%,#fff 66%) right/300% 100%;
animation:hide 3s linear infinite alternate;
}
.boxes {
width: 10%;
height: 50px;
background: tomato;
border: 1px solid #ccc;
box-sizing:border-box;
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
}
.boxes:nth-child(odd) {
background: orange;
margin-top: 40px;
}
#keyframes hide {
100% {
-webkit-mask-position:left;
mask-position:left;
}
}
body {
background:grey;
overflow:hidden;
}
<div class="wrapper">
<div class="boxes">1</div>
<div class="boxes">2</div>
<div class="boxes">3</div>
<div class="boxes">4</div>
<div class="boxes">5</div>
<div class="boxes">6</div>
<div class="boxes">7</div>
<div class="boxes">8</div>
<div class="boxes">9</div>
<div class="boxes">10</div>
</div>
I have a background image (a schematic) spinning. But I need the center of that image to be lower.
If you think of it like a spinning disc, we should only see the top of the disc, and not the bottom.
I need it to stay within the same border/frame area.
I need the 'product images' to stay centered where they are.
You can see what I have here:
http://www.meteorsite.com/images/spinner/
Thanks in advance for any suggestions...
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$('#slideshow > div:first')
.fadeOut(3000).next().fadeIn(3000).end()
.appendTo('#slideshow');console.log($('#slideshow > div:first').height()+'-'+$('#slideshow > div:first').width())
}, 5000);
*{margin:0;padding:0;box-sizing:border-box}
#slideshow {
text-align: center;
width: 100%;
height: 100%;
top: 50;
left: 0;
right: 0;
bottom: 0;
}
#slideshow > div {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.wrapper {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
animation: bend 1s linear 0s alternate; /*linear XS is delay before disc
flaps down*/
-webkit-animation-fill-mode: forwards;
}
.vinyl {
width: 600px;
height: 600px;
border-radius: 50%;
animation: moveLeft 0s linear 0s alternate, spin 30s linear 0s infinite; /*
time to spin, etc */
}
.vinyl div {
border: 0px solid #222;
box-sizing: border-box;
height: 100%;
width: 100%;
padding: 5px;
border-radius: 50%;
}
.vinyl__label {
border: none;
background: white;
color: white;
text-align: center;
background-image: url(schemo.gif);
background-size: cover;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
}
#keyframes spin {
0% {
transform: rotateZ(0deg) rotateY(0deg);
}
25% {
transform: rotateZ(90deg) rotateY(0deg);
}
75% {
transform: rotateZ(270deg) rotateY(0deg);
}
100% {
transform: rotateZ(360deg) rotateY(0deg);
}
}
#keyframes bend { /* how far the disc leans back*/
from {
transform: rotateX(55deg);
}
to {
transform: rotateX(55deg);
}
}
#keyframes moveLeft {
transition: all 2s ease-in-out;
-webkit-transition: all 2s ease-in-out;
/** Chrome & Safari **/
-moz-transition: all 2s ease-in-out;
/** Firefox **/
-o-transition: all 2s ease-in-out;
/** Opera **/
from {
transform: translate(350px, 0);
}
to {
transform: translate(350px, 0);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position: absolute;left: 0;right: 0;margin: auto">
<div class="wrapper" style="position: relative;">
<div style="box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);">
<div class="vinyl">
<div class="vinyl__label">
<i class="fa fa-circle" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
<div id="slideshow" style="position: absolute;">
<div style="background: url("http://web3designs.com/spin/slide-1.gif") center center no-repeat;"></div><div style="background: url("http://web3designs.com/spin/slide-2.gif") center center no-repeat; display: none;"></div><div style="background: url("http://web3designs.com/spin/slide-3.gif") center center no-repeat; display: none;"></div></div>
</div>
Here is a quick draft of the disc's position:
You have to add perspective to your .wrapper to make it true 3D.
Then rotate .vinyl around X axis to set a view angle and spin, spin, spin around Z axis:
$(() => {
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$('#slideshow > div:first')
.fadeOut(3000).next().fadeIn(3000).end()
.appendTo('#slideshow');
//console.log($('#slideshow > div:first').height() + '-' + $('#slideshow > div:first').width())
}, 5000);
})
* {
margin: 0;
padding: 0;
box-sizing: border-box
}
#slideshow {
text-align: center;
width: 100%;
height: 100%;
top: 50;
left: 0;
right: 0;
bottom: 0;
}
#slideshow>div {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.wrapper {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
animation: bend 1s linear 0s alternate;
/*linear XS is delay before disc
flaps down*/
-webkit-animation-fill-mode: forwards;
perspective:1000px;
}
.wrapper > div {overflow:hidden; box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);}
.vinyl {
width: 600px;
height: 600px;
border-radius: 50%; border:solid 1px;
transform: translateY(50%) rotateX(60deg) rotateZ(0);
animation: moveLeft 0s linear 0s alternate, spin 30s linear 0s infinite;
/*
time to spin, etc */
}
.vinyl div {
border: 0px solid #222;
box-sizing: border-box;
height: 100%;
width: 100%;
padding: 5px;
border-radius: 50%;
}
.vinyl__label {
border: none;
background: white;
color: white;
text-align: center;
background-image: url(https://etap.com/images/default-source/product/electrical-single-line-diagram/electrical-single-line-diagram-53a2be6450c286c028629ff00005ae238.jpg?sfvrsn=14);
background-size: cover;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
}
#keyframes spin {
100% {
transform: translateY(50%) rotateX(60deg) rotateZ(360deg);
}
}
#keyframes bend {
/* how far the disc leans back*/
from {
transform: rotateX(55deg);
}
to {
transform: rotateX(55deg);
}
}
#keyframes moveLeft {
transition: all 2s ease-in-out;
-webkit-transition: all 2s ease-in-out;
/** Chrome & Safari **/
-moz-transition: all 2s ease-in-out;
/** Firefox **/
-o-transition: all 2s ease-in-out;
/** Opera **/
from {
transform: translate(350px, 0);
}
to {
transform: translate(350px, 0);
}
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position: absolute;left: 0;right: 0;margin: auto">
<div class="wrapper" style="position: relative;">
<div>
<div class="vinyl">
<div class="vinyl__label">
<i class="fa fa-circle" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
<div id="slideshow" style="position: absolute">
<div style="background: url(http://web3designs.com/spin/slide-1.gif) center center no-repeat;"></div>
<div style="background: url(http://web3designs.com/spin/slide-2.gif) center center no-repeat; display: none;"></div>
<div style="background: url(http://web3designs.com/spin/slide-3.gif) center center no-repeat; display: none;"></div>
</div>
</div>