My toggled class rotates an element clockwise on 180 degrees when assigned. How can I modify my css to rotate an element from 180 to 0 degrees clockwise when toggled class removes?
var el = document.getElementById("wrapper");
el.addEventListener("click", function(){
this.classList.toggle("toggled");
});
#wrapper {
position: relative;
top: 20px;
left: 20px;
padding: 10px;
cursor: pointer;
display: inline-block;
}
#wrapper.toggled {
transform: rotateZ(180deg);
}
#wrapper > div {
width: 35px;
height: 3px;
margin-bottom: 10px;
background-color: #3f51b5;
}
#wrapper > div:last-child {
margin-bottom: 0;
}
#wrapper, #wrapper > div {
transition-property: transform;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0.35, 0, 0.25, 1);
}
#wrapper.toggled >div:first-child {
transform: rotateZ(45deg) rotateY(45deg) translateX(14px) translateY(-3px);
}
#wrapper.toggled >div:last-child {
transform: rotateZ(-45deg) rotateY(45deg) translateY(3px) translateX(14px);
}
<div id="wrapper">
<div></div>
<div></div>
<div></div>
</div>
I did some edits on your script and style and it work fine : https://jsfiddle.net/IA7medd/rkk0zc8k/
HTML:
<div id="wrapper">
<div></div>
<div></div>
<div></div>
</div>
css:
#wrapper {
position: relative;
top: 20px;
left: 20px;
padding: 10px;
cursor: pointer;
display: inline-block;
transform: rotateZ(0deg);
}
#wrapper > div {
width: 35px;
height: 3px;
margin-bottom: 10px;
background-color: #3f51b5;
}
#wrapper > div:last-child {
margin-bottom: 0;
}
#wrapper, #wrapper > div {
transition-property: transform;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0.35, 0, 0.25, 1);
}
#wrapper.toggled >div:first-child {
transform: rotateZ(45deg) rotateY(45deg) translateX(14px) translateY(-3px);
}
#wrapper.toggled >div:last-child {
transform: rotateZ(-45deg) rotateY(45deg) translateY(3px) translateX(14px);
}
.animated {
-webkit-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
animation-duration: 0.5s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.notAnimated {
-webkit-animation-duration: 0s;
-moz-animation-duration: 0s;
-o-animation-duration: 0s;
animation-duration: 0s;
}
#-webkit-keyframes rotate180 {
0%{transform: rotateZ(0deg);}
100% {transform: rotateZ(180deg);}
}
#-moz-keyframes rotate180 {
0%{transform: rotateZ(0deg);}
100% {transform: rotateZ(180deg);}
}
#-o-keyframes rotate180 {
0%{transform: rotateZ(0deg);}
100% {transform: rotateZ(180deg);}
}
#keyframes rotate180 {
0%{transform: rotateZ(0deg);}
100% {transform: rotateZ(180deg);}
}
.animated.rotate180 {
-webkit-animation-name: rotate180;
-moz-animation-name: rotate180;
-o-animation-name: rotate180;
animation-name: rotate180;
}
#-webkit-keyframes rotate360 {
0%{transform: rotateZ(180deg);}
100% {transform: rotateZ(360deg);}
}
#-moz-keyframes rotate360 {
0%{transform: rotateZ(180deg);}
100% {transform: rotateZ(360deg);}
}
#-o-keyframes rotate360 {
0%{transform: rotateZ(180deg);}
100% {transform: rotateZ(360deg);}
}
#keyframes rotate360 {
0%{transform: rotateZ(180deg);}
100% {transform: rotateZ(360deg);}
}
.animated.rotate360 {
-webkit-animation-name: rotate360;
-moz-animation-name: rotate360;
-o-animation-name: rotate360;
animation-name: rotate360;
}
#-webkit-keyframes rotate0 {
0%{transform: rotateZ(360deg);}
100% {transform: rotateZ(0deg);}
}
#-moz-keyframes rotate0 {
0%{transform: rotateZ(360deg);}
100% {transform: rotateZ(0deg);}
}
#-o-keyframes rotate0 {
0%{transform: rotateZ(360deg);}
100% {transform: rotateZ(0deg);}
}
#keyframes rotate0 {
0%{transform: rotateZ(360deg);}
100% {transform: rotateZ(0deg);}
}
.animated.rotate0 {
-webkit-animation-name: rotate0;
-moz-animation-name: rotate0;
-o-animation-name: rotate0;
animation-name: rotate0;
}
the script:
var el = document.getElementById("wrapper");
var counter = 1;
el.addEventListener("click", function(){
this.classList.toggle("toggled");
if(counter > 2){
counter = 1;
this.classList.toggle("rotate360");
}
if(counter == 1){
this.classList.toggle("rotate180");
}
else if(counter == 2){
this.classList.toggle("rotate180");
this.classList.toggle("rotate360");
}
counter++;
});
Another Solution :
And this is another option but using jquery : https://jsfiddle.net/IA7medd/pr9akayk/
in the option you will need only to change your script like this :
var currentRotate = 0;
var $el = $("#wrapper");
$('#wrapper').click(function(){
currentRotate+=180;
$(this).toggleClass('toggled');
$el.css({ WebkitTransform: 'rotate(' + currentRotate + 'deg)'});
$el.css({ '-moz-transform': 'rotate(' + currentRotate + 'deg)'});
})
Related
I'm not sure how to describe it, so look at this example:
$('button').on('click', () => {
$('.spinner').addClass('paused');
});
.spinner {
}
.spinner > div {
width: 25px;
height: 25px;
background-color: #9f9f9f;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner.paused > div {
-webkit-animation: sk-pause 1.4s 1 ease-in-out both;
animation: sk-pause 1.4s 1 ease-in-out both;
// -webkit-animation-play-state: paused; /* Safari 4.0 - 8.0 */
// animation-play-state: paused;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
#-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0.3) }
40% { -webkit-transform: scale(1.0) }
}
#keyframes sk-pause {
80%, 100% {transform: scale(0.3)}
}
#keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
transform: scale(0.3);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<button> Click </button>
You have three balls, that are bouncing. When you click the button it adds a class paused, which animates to the smallest visible ball. But when you click, they all come from 1.0 scale to 0.3 scale. I would like that they transition from their previous state to 0.3.
Please see this:
<head>
<title></title>
<style>
.spinner {
}
.spinner > div {
width: 25px;
height: 25px;
background-color: #9f9f9f;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner.paused > div {
-webkit-animation: sk-pause 1.4s 1 ease-in-out both;
animation: sk-pause 1.4s 1 ease-in-out both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
#-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
}
40% {
-webkit-transform: scale(1.0);
}
}
#keyframes sk-pause {
80%, 100% {
transform: scale(0.3);
}
}
#keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0.3);
transform: scale(0.3);
}
40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div class="spinner">
<div id="div1" class="bounce1"></div>
<div id="div2" class="bounce2"></div>
<div id="div3" class="bounce3"></div>
</div>
<input type="button" id="a" value="Pause" />
<script>
$('#a').click(function ()
{
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle2 = window.getComputedStyle(document.getElementById("div2"));
var computedStyle3 = window.getComputedStyle(document.getElementById("div3"));
$('#div1').css('transform', computedStyle1.transform).css('-webkit-transform', computedStyle1.transform);
$('#div2').css('transform', computedStyle2.transform).css('-webkit-transform', computedStyle2.transform);
$('#div3').css('transform', computedStyle3.transform).css('-webkit-transform', computedStyle3.transform);
$('.spinner').addClass('paused');
});
</script>
</body>
I do not know what is React but I think the code must be some think like this (instead of $('#a').click(function ().... block code):
$('#a').on('click', () => {
var computedStyle1 = window.getComputedStyle(document.getElementById("div1"));
var computedStyle2 = window.getComputedStyle(document.getElementById("div2"));
var computedStyle3 = window.getComputedStyle(document.getElementById("div3"));
$('#div1').css('transform', computedStyle1.transform).css('-webkit-transform', computedStyle1.transform);
$('#div2').css('transform', computedStyle2.transform).css('-webkit-transform', computedStyle2.transform);
$('#div3').css('transform', computedStyle3.transform).css('-webkit-transform', computedStyle3.transform);
$('.spinner').addClass('paused');
});
I want to create a div which automatic slides in when calling the webpage and the ability to close it with a X and if not press X automatic closes after 5 sec.
So lets say: from top of webpage slide in and div is 200px width and is 200px height.
How can I create that with css3 transitions?
Follow below code for your slider div using css3:
First add below CSS in your html:
<style>
.slider {
background: #000;
color: #fff;
height: 20px;
position: relative;
padding: 30px;
-moz-animation-name: dropSlider;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-out;
-moz-animation-duration: 1s;
-webkit-animation-name: dopSlider;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-out;
-webkit-animation-duration: 1s;
animation-name: dropSlider;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
}
#-moz-keyframes dropSlider {
0% {
-moz-transform: translateY(-250px);
}
100$ {
-mox-transform: translateY(0);
}
}
#-webkit-keyframes dropSlider {
0% {
-webkit-transform: translateY(-250px);
}
100% {
-webkit-transform: translateY(0);
}
}
#keyframes dropSlider {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
#divSlider.close {
opacity:0;
}
button {
position: absolute;
top: 0px;
right: 0px;
}
</style>
Now, add the below code in your body part:
<div align='center'>
<div id='divSlider' class='slider' style='height:200px; width:200px; border:solid;'>
<button type='button' onclick='closeMe();'>X</button>
<h1>Slider Div</h1>
</div>
</div>
then finally add the below script after the end of the body:
<script>
setTimeout(function() {
document.getElementById('divSlider').className = 'close';
}, 5000);
function closeMe() {
document.getElementById('divSlider').className = 'close';
}
</script>
Finally, your html is ready to execute....
I'm sure this'll help you solve out your issue and if it's does then don't forget to mark my answer... (^_^)
Thanks...
setTimeout(function() {
document.getElementById('divSlider').className = 'close';
}, 5000);
function closeMe() {
document.getElementById('divSlider').className = 'close';
}
.slider {
background: #000;
color: #fff;
height: 20px;
position: relative;
padding: 30px;
-moz-animation-name: dropSlider;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-out;
-moz-animation-duration: 1s;
-webkit-animation-name: dopSlider;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-out;
-webkit-animation-duration: 1s;
animation-name: dropSlider;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
}
#-moz-keyframes dropSlider {
0% {
-moz-transform: translateY(-250px);
}
100$ {
-mox-transform: translateY(0);
}
}
#-webkit-keyframes dropSlider {
0% {
-webkit-transform: translateY(-250px);
}
100% {
-webkit-transform: translateY(0);
}
}
#keyframes dropSlider {
0% {
transform: translateY(-250px);
}
100% {
transform: translateY(0);
}
}
#divSlider.close {
opacity: 0;
}
button {
position: absolute;
top: 0px;
right: 0px;
}
<div align='center'>
<div id='divSlider' class='slider' style='height:200px; width:200px; border:solid;'>
<button type='button' onclick='closeMe();'>X</button>
<h1>Slider Div</h1>
</div>
</div>
I have 2 div ("a" and "b") I'm trying when div "a" slide Up and stop, div "b"
slide Up inside div "a".
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUp"> </div>
</div>
Here is my JSFiddle
#a {
width: 100px;
height: 50px;
background-color: #000;
border-radius: 10px;
margin: 0 auto;
position: relative;
}
#b {
width: 100%;
height: 10px;
background-color: #860169;
position: absolute;
bottom: 0;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.infinite {
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
.animated.hinge {
-webkit-animation-duration: 2s;
animation-duration: 2s;
}
.animated.bounceIn,
.animated.bounceOut {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
.animated.flipOutX,
.animated.flipOutY {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
#-webkit-keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
#keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
.slideInUp {
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
}
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUpChild"> </div>
</div>
translate3d(0, y%, 0) will only translate the element in Y-axis by y% the height of the element. That is 100% would translate it by 10px (height of the child) and 10% would translate it by 1px. In addition you are positioning the element at the bottom of the parent and hence translating it by 1px (end state) is not going to have any visual effect.
You need to do the following changes to achieve the effect that you are looking for:
Use a different animation for the child element, which will move the element from bottom: 0px to bottom: calc(100% - 10px) (the minus 10px is for the height of the element). The first keyframe at bottom: 0px positions the element at the bottom of the container and then gradually move it to the top of the parent element.
Add an animation-delay to the child element that is equal to the animation-duration of parent element. This is required to make sure that the child element does not start animation before the parent element has reached the top.
Note that since you have border-radius set the to the child for the bottom-left and bottom-right, the element won't look nice once it has reached the top.
#a {
width: 100px;
height: 50px;
background-color: #000;
border-radius: 10px;
margin: 0 auto;
position: relative;
}
#b {
width: 100%;
height: 10px;
background-color: #860169;
position: absolute;
bottom: 0;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.infinite {
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
.animated.hinge {
-webkit-animation-duration: 2s;
animation-duration: 2s;
}
.animated.bounceIn,
.animated.bounceOut {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
.animated.flipOutX,
.animated.flipOutY {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
#-webkit-keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
#keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
.slideInUp {
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
-webkit-animation-duration: 1s;
animation-duration: 1s;
}
.slideInUpChild {
-webkit-animation-name: slideInUpChild;
animation-name: slideInUpChild;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes slideInUpChild {
from {
bottom: 0;
}
to {
bottom: calc(100% - 10px);
}
}
#keyframes slideInUpChild {
from {
bottom: 0;
}
to {
bottom: calc(100% - 10px);
}
}
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUpChild"> </div>
</div>
One simple way to overcome the border-radius problem that I have mentioned above would be to do away with the border-radius and let the overflow: hidden setting on the parent take care of it.
#a {
width: 100px;
height: 50px;
background-color: #000;
border-radius: 10px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#b {
width: 100%;
height: 10px;
background-color: #860169;
position: absolute;
bottom: 0;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.infinite {
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
.animated.hinge {
-webkit-animation-duration: 2s;
animation-duration: 2s;
}
.animated.bounceIn,
.animated.bounceOut {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
.animated.flipOutX,
.animated.flipOutY {
-webkit-animation-duration: .75s;
animation-duration: .75s;
}
#-webkit-keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
#keyframes slideInUp {
from {
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
visibility: visible;
}
to {
-webkit-transform: translate3d(0, 10%, 0);
transform: translate3d(0, 10%, 0);
}
}
.slideInUp {
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
-webkit-animation-duration: 1s;
animation-duration: 1s;
}
.slideInUpChild {
-webkit-animation-name: slideInUpChild;
animation-name: slideInUpChild;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes slideInUpChild {
from {
bottom: 0;
}
to {
bottom: calc(100% - 10px);
}
}
#keyframes slideInUpChild {
from {
bottom: 0;
}
to {
bottom: calc(100% - 10px);
}
}
<div id="a" class="animated slideInUp">
<div id="b" class="animated slideInUpChild"> </div>
</div>
I'm using CSS keyframe animations to create some simple animated text and animation-fill-mode:forward is working for most of it to keep the properties after the animation fires except for the video element. It goes back to it's previous state. I cannot find anything that would be causing it.
Here's a codepen.
HTML:
<div class="fade-in first">
<h1 class="shrink first">Take a sigh of relief</h1></div>
<div class="fade-in second"><h1 class="shrink second">Bluebeam is not your typical software company</h1></div>
<div class="fade-in animation third">
<h1>Why? Well we often have conversations like this</h1>
</div>
<div class="row zoom-in">
<div class="col-md-10 col-md-offset-1">
<div class="flex-video widescreen">
<iframe width="560" height="315" src="//www.youtube.com/embed/brWPoUWUCJs" frameborder="0" allowfullscreen></iframe>
</div>
See more of these<i class="icon-caret-right"></i>
</div>
</div>
SASS:
.home-animation {
padding-top:60px;
}
.fade-in {
animation-name: fadeInUp;
animation-iteration-count: once;
animation-duration: 2s;
&.first {
max-height: 10px;
}
}
.fade-in.second {
max-height: 30px;
opacity:0;
animation-delay:3s;
animation-fill-mode: forwards;
}
.fade-in.third {
opacity:0;
animation-duration: 3s;
animation-delay:7s;
animation-fill-mode: forwards;
}
#keyframes fadeInUp {
0% {
opacity: 0;
transform: translate3d(0, 100%, 0);
}
100% {
opacity: 1;
transform: none;
}
}
.shrink {
animation-name: zoomOut;
animation-iteration-count: once;
animation-duration: 2s;
}
.shrink.first {
animation-delay:3s;
animation-fill-mode: forwards;
}
.shrink.second {
animation-delay:7s;
animation-fill-mode: forwards;
}
#keyframes zoomOut {
0% {
transform: scale(1) translateY(0);
color: $black;
}
100% {
transform: scale(.5) translateY(-100px);
color: $gray;
}
}
.zoom-in {
animation-name: zoomIn;
animation-iteration-count: once;
opacity:0;
animation-delay:10s;
animation-duration: 1s;
animation-fill-mode: forwards;
}
#keyframes zoomIn {
0% {
opacity: 0;
transform: scale3d(.8, .8, .8);
}
50% {
opacity: 1;
transform: scale3d(1, 1, 1);
}
}
It's because you defined only 0% and 50% in your zoomIn animation. Using 100% instead works.
#keyframes zoomIn {
0% {
opacity: 0;
transform: scale3d(.8, .8, .8);
}
100% {
opacity: 1;
transform: scale3d(1, 1, 1);
}
}
http://codepen.io/anon/pen/jPLKRp
Sorry for the vague title, but essentially I copied some code from CodePen where it works flawlessly, but I can't get the exact same code to work in my project, or a jsFiddle I created.
Here's the relevant HTML:
<div class="loader loader--flipDelay loader--3d">
<span class="loader-item">1</span>
...
</div>
And the CSS for webkit browsers:
.loader-item {
display: inline-block;
width: 50px;
height: 50px;
margin-left: 2px;
background-color: rgba(61, 92, 126, 0.7);
color: rgba(61, 92, 126, 0.7);
-webkit-animation-duration: 2000ms;
-webkit-animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);
-webkit-animation-iteration-count: infinite;
}
.loader--flipDelay .loader-item {
-webkit-animation-name: flipDelay;
}
#keyframes flipDelay {
0% {
transform: rotateX(0deg);
transform-origin: 0 0 0;
opacity: 1;
}
30% {
transform: rotateX(90deg);
transform-origin: 0 0 0;
opacity: 0;
}
40% {
transform-origin: 0 0 0;
}
60% {
transform: rotateX(90deg);
opacity: 0;
transform-origin: 0 100% 0;
}
90% {
transform: rotateX(0deg);
opacity: 1;
transform-origin: 0 100% 0;
}
}
Here's the CodePen which looks great.
I attempted to copy all the code into my project, and the elements are there, but absolutely nothing happens to them.
Here's a jsFiddle which shows the code not running. Please note that this code is only prefixed to work in Chrome and other webkit browsers.
My first thought was that it was a prefixing problem, but after removing all the warnings, still nothing happens to those loader-items.
Your code is missing -webkit- prefixes for #keyframes.
I've added vendor prefix for the rest of the browsers as well.
Fiddle
body {
font-family: 'PT Sans', sans-serif;
text-align: center;
background-color: #000;
padding-top: 40px;
}
h1,
h2 {
background-color: rgba(200, 200, 200, 0.2);
padding: 20px;
text-transform: uppercase;
color: #fff;
}
h1 {
font-size: 24px;
margin-bottom: 40px;
}
h1 a {
display: block;
margin-top: 10px;
text-transform: none;
color: #aaa;
font-size: 16px;
text-decoration: none;
}
h2 {
font-size: 16px;
margin-bottom: 15%;
}
.loader {
display: block;
overflow: hidden;
margin-bottom: 15%;
font-size: 0;
}
.loader--3d {
transform-style: preserve-3d;
-webkit-perspective: 800px;
perspective: 800px;
}
.loader--slideBoth {
overflow: visible;
}
.loader-item {
display: inline-block;
width: 50px;
height: 50px;
margin-left: 2px;
background-color: rgba(61, 92, 126, 0.7);
color: rgba(61, 92, 126, 0.7);
-webkit-animation-duration: 2000ms;
-webkit-animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);
-webkit-animation-iteration-count: infinite;
animation-duration: 2000ms;
animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);
animation-iteration-count: infinite;
}
.loader-item:nth-child(1) {
-webkit-animation-delay: 100ms;
animation-delay: 100ms;
}
.loader-item:nth-child(2) {
-webkit-animation-delay: 200ms;
animation-delay: 200ms;
}
.loader-item:nth-child(3) {
-webkit-animation-delay: 300ms;
animation-delay: 300ms;
}
.loader-item:nth-child(4) {
-webkit-animation-delay: 400ms;
animation-delay: 400ms;
}
.loader-item:nth-child(5) {
-webkit-animation-delay: 500ms;
animation-delay: 500ms;
}
.loader-item:nth-child(6) {
-webkit-animation-delay: 600ms;
animation-delay: 600ms;
}
.loader--slowFlip .loader-item {
-webkit-animation-name: slowFlip;
animation-name: slowFlip;
}
.loader--flipHoz .loader-item {
-webkit-animation-name: flipHoz;
animation-name: flipHoz;
}
.loader--fade .loader-item {
-webkit-animation-name: fade;
-webkit-animation-duration: 1000ms;
animation-duration: 1000ms;
animation-name: fade;
}
.loader--slowFlip .loader-item:nth-child(1),
.loader--flipHoz .loader-item:nth-child(1) {
-webkit-animation-delay: 150ms;
animation-delay: 150ms;
}
.loader--slowFlip .loader-item:nth-child(2),
.loader--flipHoz .loader-item:nth-child(2) {
-webkit-animation-delay: 300ms;
animation-delay: 300ms;
}
.loader--slowFlip .loader-item:nth-child(3),
.loader--flipHoz .loader-item:nth-child(3) {
-webkit-animation-delay: 450ms;
animation-delay: 450ms;
}
.loader--slowFlip .loader-item:nth-child(4),
.loader--flipHoz .loader-item:nth-child(4) {
-webkit-animation-delay: 600ms;
animation-delay: 600ms;
}
.loader--slowFlip .loader-item:nth-child(5),
.loader--flipHoz .loader-item:nth-child(5) {
-webkit-animation-delay: 750ms;
animation-delay: 750ms;
}
.loader--slowFlip .loader-item:nth-child(6),
.loader--flipHoz .loader-item:nth-child(6) {
-webkit-animation-delay: 900ms;
animation-delay: 900ms;
}
.loader--flipDelay .loader-item {
-webkit-animation-name: flipDelay;
animation-name: flipDelay;
}
.loader--flipDelayDown .loader-item {
-webkit-animation-name: flipDelay;
-webkit-animation-direction: reverse;
animation-name: flipDelay;
animation-direction: reverse;
}
.loader--slideDown .loader-item,
.loader--slideUp .loader-item {
-webkit-animation-name: slideDown;
-webkit-animation-duration: 800ms;
-webkit-animation-timing-function: linear;
animation-name: slideDown;
animation-duration: 800ms;
animation-timing-function: linear;
}
.loader--slideDown .loader-item {
transform-origin: top left;
}
.loader--slideUp .loader-item {
transform-origin: bottom left;
}
.loader--slideBoth .loader-item {
-webkit-animation-name: slideBoth;
-webkit-animation-duration: 1000ms;
transform-origin: bottom left;
-webkit-animation-timing-function: linear;
animation-name: slideBoth;
animation-duration: 1000ms;
animation-timing-function: linear;
}
/**********************************/
/* KEYFRAME ANIMATION DEFINITIONS */
/**********************************/
#-webkit-keyframes slowFlip {
0% {
transform: rotateX(0deg);
}
40% {
transform: rotateX(180deg);
}
100% {
transform: rotateX(180deg);
}
}
#-webkit-keyframes flipHoz {
0% {
transform: rotateY(0deg);
}
40% {
transform: rotateY(180deg);
}
100% {
transform: rotateY(180deg);
}
}
#-webkit-keyframes fade {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#-webkit-keyframes flipDelay {
0% {
transform: rotateX(0deg);
transform-origin: 0 0 0;
opacity: 1;
}
30% {
transform: rotateX(90deg);
transform-origin: 0 0 0;
opacity: 0;
}
40% {
transform-origin: 0 0 0;
}
60% {
transform: rotateX(90deg);
opacity: 0;
transform-origin: 0 100% 0;
}
90% {
transform: rotateX(0deg);
opacity: 1;
transform-origin: 0 100% 0;
}
}
#-webkit-keyframes slideDown {
0% {
transform: rotateX(0deg);
}
50% {
transform: rotateX(90deg);
}
}
#-webkit-keyframes slideBoth {
0% {
transform: rotateX(0deg);
}
100% {
transform: rotateX(360deg);
}
}
#keyframes slowFlip {
0% {
transform: rotateX(0deg);
}
40% {
transform: rotateX(180deg);
}
100% {
transform: rotateX(180deg);
}
}
#keyframes flipHoz {
0% {
transform: rotateY(0deg);
}
40% {
transform: rotateY(180deg);
}
100% {
transform: rotateY(180deg);
}
}
#keyframes fade {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes flipDelay {
0% {
transform: rotateX(0deg);
transform-origin: 0 0 0;
opacity: 1;
}
30% {
transform: rotateX(90deg);
transform-origin: 0 0 0;
opacity: 0;
}
40% {
transform-origin: 0 0 0;
}
60% {
transform: rotateX(90deg);
opacity: 0;
transform-origin: 0 100% 0;
}
90% {
transform: rotateX(0deg);
opacity: 1;
transform-origin: 0 100% 0;
}
}
#keyframes slideDown {
0% {
transform: rotateX(0deg);
}
50% {
transform: rotateX(90deg);
}
}
#keyframes slideBoth {
0% {
transform: rotateX(0deg);
}
100% {
transform: rotateX(360deg);
}
}
<h1>A collection of loaders using CSS 2D and 3D transforms created by #AshNolan_</h1>
<h2>Flip Delay Up</h2>
<div class="loader loader--flipDelay loader--3d"> <span class="loader-item">1</span>
<span class="loader-item">2</span>
<span class="loader-item">3</span>
<span class="loader-item">4</span>
<span class="loader-item">5</span>
<span class="loader-item">6</span>
</div>
That's not CSS. That's Sass, a language that compiles to CSS; while it doesn't add new styling capabilities (that's the browser's job), it does have a lot of language features that let you write simpler, cleaner, and less repetitive stylesheets. No browser can use Sass out of the gate; it has to be compiled to CSS first.
True as that is, I missed the point of the question. See the answer(s) above.