Right side wave is not visible [duplicate] - javascript

I want a Radar wave animation like this:
With a lot of effort using my poor knowledge of Svgs I added the left side of the desired wave and it works fine. but I need some help to add the right side with a proper solution.
Note: if you know any source code or any better solution to achieve such animation which is simpler than mine please fell free to notify me.
Note 2: I need a function to initiate the animation.
Thanks in advance.
function Wave() {
const waves = document.querySelectorAll(".radio-wave");
waves.forEach(wave => wave.classList.add('add-wave'));
const wave1 = document.querySelector(".radio-wave-1");
wave1.classList.add('add-radio-wave-1');
const wave2 = document.querySelector(".radio-wave-2");
wave2.classList.add('add-radio-wave-2');
const wave3 = document.querySelector(".radio-wave-3");
wave3.classList.add('add-radio-wave-3');
const wave4 = document.querySelector(".radio-wave-4");
wave4.classList.add('add-radio-wave-4');
const wave5 = document.querySelector(".radio-wave-5");
wave5.classList.add('add-radio-wave-5');
const wave6 = document.querySelector(".radio-wave-6");
wave6.classList.add('add-radio-wave-6');
}
setTimeout(() => Wave(), 2000);
body {
background: black;
}
.left-wave-container {
position: relative;
margin-right: 50%;
padding: 0;
font-size: 16px;
}
.radio-wave-container {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
margin: 5rem;
}
.radio-wave-container.content {
flex-flow: row nowrap;
width: 100%;
}
.radio-source {
position: absolute;
right: 2rem;
width: 2rem;
fill: #fcba03;
}
.add-wave {
-webkit-animation-duration: 2.2s;
animation-duration: 2.2s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
.radio-wave {
position: absolute;
right: 2rem;
stroke-linecap: round;
stroke-width: 4;
stroke: #fcba03;
fill: none;
transform: scale(0.2) translateX(150%);
opacity: 0;
width: 5rem;
height: 5rem;
}
.add-radio-wave-1 {
-webkit-animation-name: wave-1;
animation-name: wave-1;
-webkit-animation-delay: 0s;
animation-delay: 0s;
}
#-webkit-keyframes wave-1 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-1 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-2 {
-webkit-animation-name: wave-2;
animation-name: wave-2;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
#-webkit-keyframes wave-2 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-2 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-3 {
-webkit-animation-name: wave-3;
animation-name: wave-3;
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
#-webkit-keyframes wave-3 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-3 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-4 {
-webkit-animation-name: wave-4;
animation-name: wave-4;
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
#-webkit-keyframes wave-4 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-4 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-5 {
-webkit-animation-name: wave-5;
animation-name: wave-5;
-webkit-animation-delay: 0.8s;
animation-delay: 0.8s;
}
#-webkit-keyframes wave-5 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-5 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-6 {
-webkit-animation-name: wave-6;
animation-name: wave-6;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes wave-6 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-6 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
<div class="left-wave-container" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg style="position:absolute;width:0;height:0;" width="0" height="0" version="1.1">
<defs>
<symbol id="radio-wave" viewBox="0 0 100 200">
<g>
<path d="M62.5,185 Q12.5,100 62.5,15" />
</g>
</symbol>
<symbol id="radio-source" viewBox="0 0 100 100">
</symbol>
</defs>
</svg>
<div class="radio-wave-container">
<div class="radio-wave-container content">
<svg class="radio-source">
<use xlink:href="#radio-source"></use>
</svg>
<svg class="radio-wave radio-wave-1">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-2">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-3">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-4">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-5">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-6">
<use xlink:href="#radio-wave"></use>
</svg>
</div>
</div>
</div>

Using
transform: rotate(180deg);
On a wrapping div will reflect the animation, so you can use it on the right side.
Example:
<div class="radio-wave-container">
<div class="radio-wave-container content">
<div class="reflect">
<svg class="radio-source">
<use xlink:href="#radio-source"></use>
</svg>
</div>
...(etc)
With the following added to the stylesheet:
.reflect {
transform: rotate(180deg);
}

Accessing elements wave1..wave6 should be like querySelectorAll:
const wave1 = document.querySelectorAll(".radio-wave-1");
...
const wave6 = document.querySelectorAll(".radio-wave-6");
Because this is a collection.
Next, I applied a for loop, specifying 2 as index to add a class for each wave1..wave6.
Also, I decided to correct your html and css layout. If you want your waves to be in the picture that you showed, then you need to do the following:
Use flex to align with each other. Add this to your css:
.wave-container {
display: flex;
justify-content: center;
}
And remove rule margin-right: 50% from .left-wave-container and .right-wave-container selectors.
Now it's done!
function Wave() {
const waves = document.querySelectorAll(".radio-wave");
const wave1 = document.querySelectorAll(".radio-wave-1");
const wave2 = document.querySelectorAll(".radio-wave-2");
const wave3 = document.querySelectorAll(".radio-wave-3");
const wave4 = document.querySelectorAll(".radio-wave-4");
const wave5 = document.querySelectorAll(".radio-wave-5");
const wave6 = document.querySelectorAll(".radio-wave-6");
waves.forEach(function(wave) {
wave.classList.add('add-wave');
for (var i = 0; i < 2; i++) {
wave1[i].classList.add('add-radio-wave-1');
wave2[i].classList.add('add-radio-wave-2');
wave3[i].classList.add('add-radio-wave-3');
wave4[i].classList.add('add-radio-wave-4');
wave5[i].classList.add('add-radio-wave-5');
wave6[i].classList.add('add-radio-wave-6');
}
});
}
setTimeout(() => Wave(), 2000);
body {
background: black;
}
.wave-container {
display: flex;
justify-content: center;
}
.left-wave-container {
position: relative;
/*margin-right: 50%;*/
padding: 0;
font-size: 16px;
}
.right-wave-container {
position: relative;
/*margin-right: 50%;*/
padding: 0;
font-size: 16px;
transform: rotate(180deg); /* flip the animation*/
}
.radio-wave-container {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
margin: 5rem;
}
.radio-wave-container.content {
flex-flow: row nowrap;
width: 100%;
}
.radio-source {
position: absolute;
right: 2rem;
width: 2rem;
fill: #fcba03;
}
.add-wave {
-webkit-animation-duration: 2.2s;
animation-duration: 2.2s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
.radio-wave {
position: absolute;
right: 2rem;
stroke-linecap: round;
stroke-width: 4;
stroke: #fcba03;
fill: none;
transform: scale(0.2) translateX(150%);
opacity: 0;
width: 5rem;
height: 5rem;
}
.add-radio-wave-1 {
-webkit-animation-name: wave-1;
animation-name: wave-1;
-webkit-animation-delay: 0s;
animation-delay: 0s;
}
#-webkit-keyframes wave-1 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-1 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-2 {
-webkit-animation-name: wave-2;
animation-name: wave-2;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
#-webkit-keyframes wave-2 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-2 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-3 {
-webkit-animation-name: wave-3;
animation-name: wave-3;
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
#-webkit-keyframes wave-3 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-3 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-4 {
-webkit-animation-name: wave-4;
animation-name: wave-4;
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
#-webkit-keyframes wave-4 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-4 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-5 {
-webkit-animation-name: wave-5;
animation-name: wave-5;
-webkit-animation-delay: 0.8s;
animation-delay: 0.8s;
}
#-webkit-keyframes wave-5 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-5 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
.add-radio-wave-6 {
-webkit-animation-name: wave-6;
animation-name: wave-6;
-webkit-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes wave-6 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
#keyframes wave-6 {
0% {
transform: scale(0.2) translateX(150%);
opacity: 0.2;
}
10% {
transform: scale(0.3) translateX(50%);
opacity: 0.3;
}
20% {
transform: scale(0.4) translateX(-40%);
opacity: 0.4;
}
30% {
transform: scale(0.5) translateX(-120%);
opacity: 0.5;
}
40% {
transform: scale(0.6) translateX(-190%);
opacity: 0.6;
}
50% {
transform: scale(0.7) translateX(-250%);
opacity: 0.7;
}
60% {
transform: scale(0.8) translateX(-300%);
opacity: 0.8;
}
70% {
transform: scale(0.9) translateX(-350%);
opacity: 0.9;
}
80% {
transform: scale(1) translateX(-400%);
}
90% {
transform: scale(1.1) translateX(-450%);
}
100% {
transform: scale(1.2) translateX(-500%);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="wave-container">
<div class="left-wave-container" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg style="position:absolute;width:0;height:0;" width="0" height="0" version="1.1">
<defs>
<symbol id="radio-wave" viewBox="0 0 100 200">
<g>
<path d="M62.5,185 Q12.5,100 62.5,15" />
</g>
</symbol>
<symbol id="radio-source" viewBox="0 0 100 100">
</symbol>
</defs>
</svg>
<div class="radio-wave-container">
<div class="radio-wave-container content">
<svg class="radio-source">
<use xlink:href="#radio-source"></use>
</svg>
<svg class="radio-wave radio-wave-1">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-2">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-3">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-4">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-5">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-6">
<use xlink:href="#radio-wave"></use>
</svg>
</div>
</div>
</div>
<div class="right-wave-container" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg style="position:absolute;width:0;height:0;" width="0" height="0" version="1.1">
<defs>
<symbol id="radio-wave" viewBox="0 0 100 200">
<g>
<path d="M62.5,185 Q12.5,100 62.5,15" />
</g>
</symbol>
<symbol id="radio-source" viewBox="0 0 100 100">
</symbol>
</defs>
</svg>
<div class="radio-wave-container">
<div class="radio-wave-container content">
<svg class="radio-source">
<use xlink:href="#radio-source"></use>
</svg>
<svg class="radio-wave radio-wave-1">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-2">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-3">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-4">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-5">
<use xlink:href="#radio-wave"></use>
</svg>
<svg class="radio-wave radio-wave-6">
<use xlink:href="#radio-wave"></use>
</svg>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

Related

how to make active and inactive onclick for 5 buttons

I have five buttons. If button A is clicked it should be active and the rest should be disabled.
Right now when click multiple times on any one of the disabled alphabet-buttons it gets activated along with whichever is active.
Each of the 5 buttons has its own function. When click on a button, the corresponding animation will start continuously. If click on same A button how can I stop the animation? How can I disable the other four buttons?
var click = 0; //track the click
$('.particletext').click(function () {
if (click == 0) {
//for first click change the onclick function to stopAnimation() for the element which is clicked and remove onclick functions of others
$('.particletext').attr("onclick", "");
$(this).attr("onclick", "stopAnimation(this)");
click++;
} else { //for second click decrease the click to 0
click--;
}
})
function stopAnimation(element) {
$(element).children('span').remove(); //remove animating particles
//for second click re-add onclick functions to all elements
$('.hearts').each(function() {
$(this).attr("onclick", "hearts()");
$(this).attr("onclick");
})
$('.bubbles').each(function() {
$(this).attr("onclick", "bubbles()");
$(this).attr("onclick");
})
$('.sunbeams').each(function() {
$(this).attr("onclick", "sunbeams()");
})
$('.confetti').each(function() {
$(this).attr("onclick", "confetti()");
})
$('.fire').each(function() {
$(this).attr("onclick", "fire()");
})
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
#-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
#keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li class="particletext hearts" onclick="hearts()"><a>A</a></li>
<li class="particletext bubbles" onclick="bubbles()"><a>B</a></li>
<li class="particletext sunbeams" onclick="sunbeams()"><a>C</a></li>
<li class="particletext confetti" onclick="confetti()"><a>D</a></li>
<li class="particletext fire" onclick="fire()"><a>E</a></li>
</ul>
Here's the solution. Some changes in js file and I've used comments to separate the changes.
//my code starts here
var click = 0; //track the click
var elementClassName;
$('.particletext').click(function () {
if (click == 0) {
elementClassName = $(this).attr('class');
//for first click change the onclick function to stopAnimation() for the element which is clicked and remove onclick functions of others
$('.particletext').attr("onclick", "");
$(this).attr("onclick", "stopAnimation(this)");
click++;
} else { //for second click decrease the click to 0
if ($(this).attr('class') == elementClassName) {
click--;
}
}
})
//my code ends here
function stopAnimation(element) {
$(element).children('span').remove(); //remove animating particles
//for second click re-add onclick functions to all elements
$('.hearts').each(function() {
$(this).attr("onclick", "hearts()");
$(this).attr("onclick");
})
$('.bubbles').each(function() {
$(this).attr("onclick", "bubbles()");
$(this).attr("onclick");
})
$('.sunbeams').each(function() {
$(this).attr("onclick", "sunbeams()");
})
$('.confetti').each(function() {
$(this).attr("onclick", "confetti()");
})
$('.fire').each(function() {
$(this).attr("onclick", "fire()");
})
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
#-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
#keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li class="particletext hearts" onclick="hearts()"><a>A</a></li>
<li class="particletext bubbles" onclick="bubbles()"><a>B</a></li>
<li class="particletext sunbeams" onclick="sunbeams()"><a>C</a></li>
<li class="particletext confetti" onclick="confetti()"><a>D</a></li>
<li class="particletext fire" onclick="fire()"><a>E</a></li>
</ul>
It is easier to do this with IDs than just using classes, because when you query classes you get all the classes, so it is then necessary to filter out only the ones you want. So, I added IDs to make the job easier to understand and faster to write.
You need to keep track of both (a) whether an animation is currently active, and (b) which animation is currently active.
You only need to use one method for event handling: either inline (e.g. onclick="fn_name" - not recommended) or external (the way it is done in this example). You were using both methods, in which it is easy for the logic to become confuzzled.
There is a neat trick to creating a function call out of a name stored in a variable:
window[var_name]();
var active=false, active_anim='';
$('.particletext').click(function () {
if (!active) {
active = true;
active_anim = this.id;
window[active_anim]();
}else{
if (this.id == active_anim){
stopAnimation(active_anim);
active = false;
}else{
stopAnimation(active_anim);
active_anim = this.id;
window[active_anim]();
}
}
});
function stopAnimation(element) {
$('#'+element).children('span').remove(); //remove animating particles
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
#-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
#keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li id="hearts" class="particletext hearts"><a>A</a></li>
<li id="bubbles" class="particletext bubbles"><a>B</a></li>
<li id="sunbeams" class="particletext sunbeams"><a>C</a></li>
<li id="confetti" class="particletext confetti"><a>D</a></li>
<li id="fire" class="particletext fire"><a>E</a></li>
</ul>
Update:
I misread your question and created an example where clicking on button A starts the animation, and then clicking on another button stops the first animation and starts the new animation.
That might not be what you want. Re-reading your question, it appears that you want to disable the other buttons if an animation is currently running, only allowing the user to click a second time on the same button in order to stop that animation.
If so, here is a revised example for you:
var active=false, active_anim='';
$('.particletext').click(function () {
if (!active) {
active = true;
active_anim = this.id;
$(this).addClass('activebox'); //<=== also added
window[active_anim]();
}else{
if (this.id == active_anim){
$('.particletext').removeClass('activebox'); //<=== also added
stopAnimation(active_anim);
active = false;
}else{
console.log('Button ' +this.id+ ' ignored')
}
}
});
function stopAnimation(element) {
$('#'+element).children('span').remove(); //remove animating particles
}
function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = 4;
for(var i = 0; i <= bubblecount; i++) {
var size = ((Math.floor( Math.random() * (80 - 40 + 1) ) + 40)/10);
$(this).append('<span class="particle" style="top:' + 27 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = 3;
for(var i = 0; i <= heartcount; i++) {
var size = ((Math.floor( Math.random() * (120 - 60 + 1) ) + 60)/10);
$(this).append('<span class="particle" style="top:' + 11 + '%; left:' + (Math.floor( Math.random() * (95 - 0 + 1) ) + 0) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = 4;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1) + '" style="top:' + (Math.floor( Math.random() * (50 - 10 + 1) ) + 10) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' + (Math.floor( Math.random() * (8 - 6 + 1) ) + 6)+ 'px; height:' + (Math.floor( Math.random() * (4 - 3+ 1) ) + 3) + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function fire() {
$.each($(".particletext.fire"), function(){
var firecount = 2;
for(var i = 0; i <= firecount; i++) {
var size = Math.floor( Math.random() * (12 - 8 + 1) ) + 8;
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (70 - 40 + 1) ) + 40) + '%; left:' + (Math.floor( Math.random() * (1 +20 + 11) ) + 1) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + 0.1 + 's;"></span>');
}
});
}
function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = 3;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + (Math.floor( Math.random() * (0 + 40 + 1) ) - 40) + '%; left:' + (Math.floor( Math.random() * (100 - 0 + 1) ) + 0) + '%;width:' +(Math.floor( Math.random() * (2 - 1 + 1) ) + 1 )+ 'px; height:' + 35 + '%;animation-delay: -' + 0.1 + 's;"></span>');
}
});
}
.particletext{border:1px solid transparent;padding:2px;}
.activebox{border:1px solid green;}
.particletext {
text-align: center;
font-size: 48px;
position: relative;
}
.particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 149, 243, 0.603);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}
.particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: rgba(204,42,93,1);
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}
.particletext.hearts > .particle:before,.particletext.hearts > .particle:after {
position: absolute;
content: '';
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: rgba(204,42,93,1);
}
.particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}
.particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}
.particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}
.particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}
.particletext.fire > .particle {
position: absolute;
background-color: rgba(7, 141, 255, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}
.particletext.fire > .particle:before {
position: absolute;
content: '';
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(0, 66, 251, 0.5);
}
.particletext.sunbeams > .particle {
position: absolute;
background-color:#dc3dd5;
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}
#-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
#-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
#-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
#-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
#-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
#-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
#keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%,14%,17%,43%,53%,71%,80%,94%,100% {
opacity: 0;
}
6%,15%,24%,28%,48%,55%,78%,82%,99% {
opacity: 1;
}
}
ul.socialIcons {
padding: 0;
text-align: center;
}
.socialIcons li {
background: #fff;
list-style: none;
display: inline-block;
margin: 0 25px;
font-size: 12px;
}
.socialIcons li a {
text-decoration: none;
color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="socialIcons">
<li id="hearts" class="particletext hearts"><a>A</a></li>
<li id="bubbles" class="particletext bubbles"><a>B</a></li>
<li id="sunbeams" class="particletext sunbeams"><a>C</a></li>
<li id="confetti" class="particletext confetti"><a>D</a></li>
<li id="fire" class="particletext fire"><a>E</a></li>
</ul>

Why does the last frame show up before first in animation?

I was trying to make a "bounce-in" effect where the circle isn't there before the animation, then the animation is executed on scroll, and the circle remains there after the animation is over. But for some reason it's there even before the animation, then disappears (since first frame opacity is 0) then appears again. I'm not sure what I'm doing wrong.
if (browser.canUse('transition')) {
var on = function() {
// Circles
$('.circle')
.scrollex({
mode: 'bottom',
delay: 50,
initialize: function() {
$(this).addClass('bounceIn');
},
terminate: function() {
$(this).removeClass('bounceIn');
},
enter: function() {
$(this).removeClass('bounceIn');
},
leave: function() {
$(this).addClass('bounceIn');
}
});
.circle {
position: absolute;
border-radius: 50%;
}
.circle.circle1 {
top: 80px;
left: 120px;
width: 100px;
height: 100px;
background: white;
opacity: 0;
}
/* ----------- BOUNCE IN ------------*/
#-webkit-keyframes bounceIn {
from,
20%,
40%,
60%,
80%,
to {
-webkit-animation-timing-function: cubic-bezier(0.315, 0.71, 0.455, 1);
animation-timing-function: cubic-bezier(0.315, 0.71, 0.455, 1);
}
0% {
opacity: 0;
-webkit-transform: scale(0.3);
transform: scale(0.3);
}
20% {
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
40% {
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
60% {
opacity: 1;
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
80% {
-webkit-transform: scale(0.97);
transform: scale(0.97);
}
to {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
}
#keyframes bounceIn {
from,
20%,
40%,
60%,
80%,
to {
-webkit-animation-timing-function: cubic-bezier(0.315, 0.71, 0.455, 1);
animation-timing-function: cubic-bezier(0.315, 0.71, 0.455, 1);
}
0% {
opacity: 0;
-webkit-transform: scale(0.3);
transform: scale(0.3);
}
20% {
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
40% {
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
60% {
opacity: 1;
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
80% {
-webkit-transform: scale(0.97);
transform: scale(0.97);
}
to {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
}
.bounceIn {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-name: bounceIn;
animation-name: bounceIn;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
<div class="circle circle1"></div>

preloader for part of content in current theme wp

I need to show preloader only in 'content' div, but preloader hides entire page. Structure site:
Title
Menu
Content (here i need preloader)
Footer
I can't find, where i need insert my code of preloader...
src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"
$(window).load(function() {
$(".cssload-loader").delay(1400).fadeOut();
$(".preloader").delay(1500).fadeOut("slow");
})
.preloader {
position: fixed;
background-color: #fff;
z-index: 107;
height: 100%;
width: 100%;
}
.cssload-loader {
position: absolute;
left: 50%;
top: 50%;
width: 34.284271247462px;
height: 34.284271247462px;
margin-left: -17.142135623731px;
margin-top: -17.142135623731px;
border-radius: 100%;
animation-name: cssload-loader;
-o-animation-name: cssload-loader;
-ms-animation-name: cssload-loader;
-webkit-animation-name: cssload-loader;
-moz-animation-name: cssload-loader;
animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
animation-timing-function: linear;
-o-animation-timing-function: linear;
-ms-animation-timing-function: linear;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
animation-duration: 2.8s;
-o-animation-duration: 2.8s;
-ms-animation-duration: 2.8s;
-webkit-animation-duration: 2.8s;
-moz-animation-duration: 2.8s;
}
.cssload-loader .cssload-side {
display: block;
width: 4px;
height: 14px;
background-color: rgba(0,0,0,0.81);
margin: 1px;
position: absolute;
border-radius: 50%;
animation-duration: 1.045s;
-o-animation-duration: 1.045s;
-ms-animation-duration: 1.045s;
-webkit-animation-duration: 1.045s;
-moz-animation-duration: 1.045s;
animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
animation-timing-function: ease;
-o-animation-timing-function: ease;
-ms-animation-timing-function: ease;
-webkit-animation-timing-function: ease;
-moz-animation-timing-function: ease;
}
.cssload-loader .cssload-side:nth-child(1),
.cssload-loader .cssload-side:nth-child(5) {
transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
animation-name: cssload-rotate0;
-o-animation-name: cssload-rotate0;
-ms-animation-name: cssload-rotate0;
-webkit-animation-name: cssload-rotate0;
-moz-animation-name: cssload-rotate0;
}
.cssload-loader .cssload-side:nth-child(3),
.cssload-loader .cssload-side:nth-child(7) {
transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
animation-name: cssload-rotate90;
-o-animation-name: cssload-rotate90;
-ms-animation-name: cssload-rotate90;
-webkit-animation-name: cssload-rotate90;
-moz-animation-name: cssload-rotate90;
}
.cssload-loader .cssload-side:nth-child(2),
.cssload-loader .cssload-side:nth-child(6) {
transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
animation-name: cssload-rotate45;
-o-animation-name: cssload-rotate45;
-ms-animation-name: cssload-rotate45;
-webkit-animation-name: cssload-rotate45;
-moz-animation-name: cssload-rotate45;
}
.cssload-loader .cssload-side:nth-child(4),
.cssload-loader .cssload-side:nth-child(8) {
transform: rotate(135deg);
-o-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
animation-name: cssload-rotate135;
-o-animation-name: cssload-rotate135;
-ms-animation-name: cssload-rotate135;
-webkit-animation-name: cssload-rotate135;
-moz-animation-name: cssload-rotate135;
}
.cssload-loader .cssload-side:nth-child(1) {
top: 17.142135623731px;
left: 34.284271247462px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(2) {
top: 29.213203431093px;
left: 29.213203431093px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(3) {
top: 34.284271247462px;
left: 17.142135623731px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(4) {
top: 29.213203431093px;
left: 5.0710678163691px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(5) {
top: 17.142135623731px;
left: 0px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(6) {
top: 5.0710678163691px;
left: 5.0710678163691px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(7) {
top: 0px;
left: 17.142135623731px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
.cssload-loader .cssload-side:nth-child(8) {
top: 5.0710678163691px;
left: 29.213203431093px;
margin-left: -2px;
margin-top: -7px;
animation-delay: 0;
-o-animation-delay: 0;
-ms-animation-delay: 0;
-webkit-animation-delay: 0;
-moz-animation-delay: 0;
}
#keyframes cssload-rotate0 {
0% {
transform: rotate(0deg);
}
60% {
transform: rotate(180deg);
}
100% {
transform: rotate(180deg);
}
}
#-o-keyframes cssload-rotate0 {
0% {
-o-transform: rotate(0deg);
}
60% {
-o-transform: rotate(180deg);
}
100% {
-o-transform: rotate(180deg);
}
}
#-ms-keyframes cssload-rotate0 {
0% {
-ms-transform: rotate(0deg);
}
60% {
-ms-transform: rotate(180deg);
}
100% {
-ms-transform: rotate(180deg);
}
}
#-webkit-keyframes cssload-rotate0 {
0% {
-webkit-transform: rotate(0deg);
}
60% {
-webkit-transform: rotate(180deg);
}
100% {
-webkit-transform: rotate(180deg);
}
}
#-moz-keyframes cssload-rotate0 {
0% {
-moz-transform: rotate(0deg);
}
60% {
-moz-transform: rotate(180deg);
}
100% {
-moz-transform: rotate(180deg);
}
}
#keyframes cssload-rotate90 {
0% {
transform: rotate(90deg);
transform: rotate(90deg);
}
60% {
transform: rotate(270deg);
transform: rotate(270deg);
}
100% {
transform: rotate(270deg);
transform: rotate(270deg);
}
}
#-o-keyframes cssload-rotate90 {
0% {
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
60% {
-o-transform: rotate(270deg);
transform: rotate(270deg);
}
100% {
-o-transform: rotate(270deg);
transform: rotate(270deg);
}
}
#-ms-keyframes cssload-rotate90 {
0% {
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
60% {
-ms-transform: rotate(270deg);
transform: rotate(270deg);
}
100% {
-ms-transform: rotate(270deg);
transform: rotate(270deg);
}
}
#-webkit-keyframes cssload-rotate90 {
0% {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
60% {
-webkit-transform: rotate(270deg);
transform: rotate(270deg);
}
100% {
-webkit-transform: rotate(270deg);
transform: rotate(270deg);
}
}
#-moz-keyframes cssload-rotate90 {
0% {
-moz-transform: rotate(90deg);
transform: rotate(90deg);
}
60% {
-moz-transform: rotate(270deg);
transform: rotate(270deg);
}
100% {
-moz-transform: rotate(270deg);
transform: rotate(270deg);
}
}
#keyframes cssload-rotate45 {
0% {
transform: rotate(45deg);
transform: rotate(45deg);
}
60% {
transform: rotate(225deg);
transform: rotate(225deg);
}
100% {
transform: rotate(225deg);
transform: rotate(225deg);
}
}
#-o-keyframes cssload-rotate45 {
0% {
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
60% {
-o-transform: rotate(225deg);
transform: rotate(225deg);
}
100% {
-o-transform: rotate(225deg);
transform: rotate(225deg);
}
}
#-ms-keyframes cssload-rotate45 {
0% {
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
60% {
-ms-transform: rotate(225deg);
transform: rotate(225deg);
}
100% {
-ms-transform: rotate(225deg);
transform: rotate(225deg);
}
}
#-webkit-keyframes cssload-rotate45 {
0% {
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
60% {
-webkit-transform: rotate(225deg);
transform: rotate(225deg);
}
100% {
-webkit-transform: rotate(225deg);
transform: rotate(225deg);
}
}
#-moz-keyframes cssload-rotate45 {
0% {
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
60% {
-moz-transform: rotate(225deg);
transform: rotate(225deg);
}
100% {
-moz-transform: rotate(225deg);
transform: rotate(225deg);
}
}
#keyframes cssload-rotate135 {
0% {
transform: rotate(135deg);
transform: rotate(135deg);
}
60% {
transform: rotate(315deg);
transform: rotate(315deg);
}
100% {
transform: rotate(315deg);
transform: rotate(315deg);
}
}
#-o-keyframes cssload-rotate135 {
0% {
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
60% {
-o-transform: rotate(315deg);
transform: rotate(315deg);
}
100% {
-o-transform: rotate(315deg);
transform: rotate(315deg);
}
}
#-ms-keyframes cssload-rotate135 {
0% {
-ms-transform: rotate(135deg);
transform: rotate(135deg);
}
60% {
-ms-transform: rotate(315deg);
transform: rotate(315deg);
}
100% {
-ms-transform: rotate(315deg);
transform: rotate(315deg);
}
}
#-webkit-keyframes cssload-rotate135 {
0% {
-webkit-transform: rotate(135deg);
transform: rotate(135deg);
}
60% {
-webkit-transform: rotate(315deg);
transform: rotate(315deg);
}
100% {
-webkit-transform: rotate(315deg);
transform: rotate(315deg);
}
}
#-moz-keyframes cssload-rotate135 {
0% {
-moz-transform: rotate(135deg);
transform: rotate(135deg);
}
60% {
-moz-transform: rotate(315deg);
transform: rotate(315deg);
}
100% {
-moz-transform: rotate(315deg);
transform: rotate(315deg);
}
}
#keyframes cssload-loader {
0% {
transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-o-keyframes cssload-loader {
0% {
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-ms-keyframes cssload-loader {
0% {
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes cssload-loader {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-moz-keyframes cssload-loader {
0% {
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<?php
get_header();
get_template_part('index', 'banner');
?>
<!-- Blog Full Width Section -->
<div class="blog-section">
<div class="container">
<div class="row">
<!--Blog Area-->
<div class="<?php elitepress_post_layout_class(); ?>" >
<?php get_template_part('content',''); ?>
<?php comments_template('',true); ?>
</div>
<!--/Blog Area-->
<div class="preloader" style="display: block;">
<div class="cssload-loader" style="display: block;">
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
<div class="cssload-side"></div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>
<!-- /Blog Full Width Section -->
A simple solution using a FontAwesome spinner. Colors used are for visualization only.
$(".spinner").delay(1400).fadeOut();
header,
nav,
footer {
width: 100%;
height: 50px;
}
header {
background-color: red;
}
nav {
background-color: blue;
}
footer {
background-color: green;
}
.content {
width: 100%;
height: 200px;
position: relative;
}
.spinner {
width: 100%;
height: 100%;
background-color: purple;
text-align: center;
display: table;
}
.spinner i {
display: table-cell;
vertical-align: middle;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<header></header>
<nav></nav>
<div class="content">
<div class="spinner"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>
</div>
<footer></footer>

Workaround for safari's buggy rendering of inner SVG Animation?

I'm looking for a workaround for safari's buggy rendering of inner SVG with CSS Animations.
Here it is on codepen.
Chrome does this perfectly well, but in Safari the transitioning within the animation doesn't render until it jumps between states.
What is causing it?
Relevant CSS3
.avatar {
z-index: 800;
}
.avatar path {
stroke: #e1afff;
stroke-width: 0.15;
-webkit-transform-origin: center center;
transform-origin: center center;
-webkit-transition: all 6s ease;
transition: all 6s ease;
-webkit-transform: translate(0);
transform: translate(0);
}
.avatar path:nth-of-type(4n+1) {
-webkit-animation: p1 3s ease 1;
animation: p1 3s ease 1;
}
.avatar path:nth-of-type(4n+2) {
-webkit-animation: p2 3s ease 1;
animation: p2 3s ease 1;
}
.avatar path:nth-of-type(4n+3) {
-webkit-animation: p3 3s ease 1;
animation: p3 3s ease 1;
}
.avatar path:nth-of-type(4n+4) {
-webkit-animation: p4 3s ease 1;
animation: p4 3s ease 1;
}
.hover {
position: absolute;
width: 40%;
height: 40vw;
top: 50%;
left: 30%;
margin-top: -20vw;
border-radius: 50%;
cursor: pointer;
z-index: 1000;
background: rgba(0,0,0,0);
-webkit-animation: waitforit 0 ease-in 3s 1 forwards;
animation: waitforit 0 ease-in 3s 1 forwards;
}
.hover:hover + .avatar path:nth-of-type(4n+1) {
-webkit-transform: translate(800%, 400%) rotate(-690deg) translateZ(0);
transform: translate(800%, 400%) rotate(-690deg) translateZ(0);
}
.hover:hover + .avatar path:nth-of-type(4n+2) {
-webkit-transform: translate(-700%, 600%) rotate(-720deg) translateZ(0);
transform: translate(-700%, 600%) rotate(-720deg) translateZ(0);
}
.hover:hover + .avatar path:nth-of-type(4n+3) {
-webkit-transform: translate(-900%, -500%) rotate(-820deg) translateZ(0);
transform: translate(-900%, -500%) rotate(-820deg) translateZ(0);
}
.hover:hover + .avatar path:nth-of-type(4n+4) {
-webkit-transform: translate(700%, -800%) rotate(-950deg) translateZ(0);
transform: translate(700%, -800%) rotate(-950deg) translateZ(0);
}
#-webkit-keyframes p1 {
0% {
-webkit-transform: translate(-300%, -700%) rotate(520deg) translateZ(0);
transform: translate(-300%, -700%) rotate(520deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#keyframes p1 {
0% {
-webkit-transform: translate(-300%, -700%) rotate(520deg) translateZ(0);
transform: translate(-300%, -700%) rotate(520deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#-webkit-keyframes p2 {
0% {
-webkit-transform: translate(400%, -900%) rotate(850deg) translateZ(0);
transform: translate(400%, -900%) rotate(850deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#keyframes p2 {
0% {
-webkit-transform: translate(400%, -900%) rotate(850deg) translateZ(0);
transform: translate(400%, -900%) rotate(850deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#-webkit-keyframes p3 {
0% {
-webkit-transform: translate(500%, 900%) rotate(325deg) translateZ(0);
transform: translate(500%, 900%) rotate(325deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#keyframes p3 {
0% {
-webkit-transform: translate(500%, 900%) rotate(325deg) translateZ(0);
transform: translate(500%, 900%) rotate(325deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#-webkit-keyframes p4 {
0% {
-webkit-transform: translate(-500%, 900%) rotate(748deg) translateZ(0);
transform: translate(-500%, 900%) rotate(748deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#keyframes p4 {
0% {
-webkit-transform: translate(-500%, 900%) rotate(748deg) translateZ(0);
transform: translate(-500%, 900%) rotate(748deg) translateZ(0);
}
100% {
-webkit-transform: translate(0);
transform: translate(0);
}
}
#-webkit-keyframes waitforit {
0% {
display: none;
}
100% {
display: block;
}
}
#keyframes waitforit {
0% {
display: none;
}
100% {
display: block;
}
}
The vendor prefix -webkit- applies to both Chrome & Safari. Safari is known to be buggy in rendering inner SVG animations, however there is usually a happy medium. Can anyone think of a workaround of sorts? Maybe an easy js fix?

Keep div static when other appears

I have a jsfiddle as follows:
http://jsfiddle.net/aritro33/uX7HG/
And I have a problem that when you hit the compose button, the post that appears gets pushed down slightly, but noticeably, by the arrangement of colors that pops up seconds later. How do I keep the post from moving as the arrangement of colors pops up?
Thanks!
HTML:
<div id="red" class = "color"></div>
<div id="orange" class = "color"></div>
<div id="yellow" class = "color"></div>
<div id="green" class = "color"></div>
<div id="turquoise" class = "color"></div>
<div id="blue" class = "color"></div>
<div id="purple" class = "color"></div>
<div id="gray" class = "color"></div>
<div id="composeheader">
<input type="text" id="secondspan" value="Write Header Here:" />
<div id = "sidebarhex"></div>
<div id = "taghex"><span id = "withhex" contenteditable = "true">#2AC0A3</span></div>
</div>
<div id="body"><span id="thirdspan" contenteditable="true">Write context text here:</span>
</div>
CSS:
#red {
background-color: #2ac0a3;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
position: relative;
bottom: 220px;
left: 365px;
}
#orange {
background-color: #25ac92;
position:relative;
bottom:236px;
left: 405px;
}
#yellow {
position: relative;
bottom: 252px;
left: 445px;
background-color:#219982;
}
#green {
position: relative;
left: 485px;
bottom: 268px;
background-color: #1d8672;
}
#turquoise {
position: relative;
left: 525px;
bottom: 284px;
background-color: #197361;
}
#blue {
position: relative;
left: 565px;
bottom: 300px;
background-color: #156051;
}
#purple {
position: relative;
left: 605px;
bottom: 316px;
background-color: #104c41;
}
#gray {
position: relative;
left: 645px;
bottom: 332px;
background-color: #0c3930;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
#composeheader {
height: 80px;
width: 500px;
background-color:#2AC0A3;
position: relative;
bottom: 320px;
left: 365px;
color: white;
}
#secondspan {
color: white;
font-family:'Roboto';
font-size: 40px;
position: relative;
background-color: #2AC0A3;
border: 1px solid #2AC0A3;
left: 15px;
top: 10px;
}
#body {
min-height: 100px;
overflow: hidden;
width: 500px;
background-color: #C6EEE6;
position: relative;
left: 365px;
bottom: 320px;
padding: 20px;
-moz-box-sizing: border-box;
box-sizing: border-box;
-ms-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#thirdspan {
color: black;
font-family:'Roboto';
outline: 0px solid transparent;
}
#sidebarhex{
height: 30px;
width: 7px;
background-color: #156051;
position: relative;
left: 500px;
bottom: 30px;
}
#taghex{
height: 30px;
width: 80px;
background-color: #219982;
position: relative;
left: 420px;
bottom: 60px;
}
#withhex{
font-family: 'Roboto';
position: relative;
top: 4px;
left: 9px;
border: 0px solid transparent;
outline: none;
}
.color{
height: 16px;
width: 40px;
}
#red.active{
height: 16px;
width: 45px;
z-index: 1;
border: 3px solid white;
position: relative;
bottom: 218px;
}
#orange.active{
height: 16px;
width: 45px;
z-index: 1;
border: 3px solid white;
position: relative;
bottom: 233px;
}
#red.orangeselected{
position: relative;
bottom: 215px;
}
Animation CSS:
.animated {
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
}
.animated.hinge {
-webkit-animation-duration: 2s;
-moz-animation-duration: 2s;
-ms-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
}
#-webkit-keyframes bounceInDown {
0% {
-webkit-transform: translateY(-2000px);
}
60% {
-webkit-transform: translateY(30px);
}
80% {
-webkit-transform: translateY(-10px)
}
100% {
-webkit-transform: translateY()
}
}
#-moz-keyframes bounceInDown {
0% {
-moz-transform: translateY(-2000px);
}
60% {
-moz-transform: translateY(30px);
}
80% {
-moz-transform: translateY(-10px)
}
100% {
-moz-transform: translateY()
}
}
#-ms-keyframes bounceInDown {
0% {
-ms-transform: translateY(-2000px);
}
60% {
-ms-transform: translateY(30px);
}
80% {
-ms-transform: translateY(-10px)
}
100% {
-ms-transform: translateY()
}
}
#-o-keyframes bounceInDown {
0% {
-o-transform: translateY(-2000px);
}
60% {
-o-transform: translateY(30px);
}
80% {
-o-transform: translateY(-10px)
}
100% {
-o-transform: translateY()
}
}
#keyframes bounceInDown {
0% {
transform: translateY(-2000px);
}
60% {
transform: translateY(30px);
}
80% {
transform: translateY(-10px)
}
100% {
transform: translateY()
}
}
.bounceInDown {
-webkit-animation-name: bounceInDown;
-moz-animation-name: bounceInDown;
-ms-animation-name: bounceInDown;
-o-animation-name: bounceInDown;
animation-name: bounceInDown;
}
#-webkit-keyframes bounceInUp {
0% {
-webkit-transform: translateY(2000px);
}
60% {
-webkit-transform: translateY(-30px);
}
80% {
-webkit-transform: translateY(10px)
}
100% {
-webkit-transform: translateY()
}
}
#-moz-keyframes bounceInUp {
0% {
-moz-transform: translateY(2000px);
}
60% {
-moz-transform: translateY(-30px);
}
80% {
-moz-transform: translateY(10px)
}
100% {
-moz-transform: translateY()
}
}
#-ms-keyframes bounceInUp {
0% {
-ms-transform: translateY(2000px);
}
60% {
-ms-transform: translateY(-30px);
}
80% {
-ms-transform: translateY(10px)
}
100% {
-ms-transform: translateY()
}
}
#-o-keyframes bounceInUp {
0% {
-o-transform: translateY(2000px);
}
60% {
-o-transform: translateY(-30px);
}
80% {
-o-transform: translateY(10px)
}
100% {
-o-transform: translateY()
}
}
#keyframes bounceInUp {
0% {
transform: translateY(2000px);
}
60% {
transform: translateY(-30px);
}
80% {
transform: translateY(10px)
}
100% {
transform: translateY()
}
}
.bounceInUp {
-webkit-animation-name: bounceInUp;
-moz-animation-name: bounceInUp;
-ms-animation-name: bounceInUp;
-o-animation-name: bounceInUp;
animation-name: bounceInUp;
}
#-webkit-keyframes bounceInUp {
0% {
-webkit-transform: translateY(2000px);
}
60% {
-webkit-transform: translateY(-30px);
}
80% {
-webkit-transform: translateY(10px)
}
100% {
-webkit-transform: translateY()
}
}
#-moz-keyframes bounceInUp {
0% {
-moz-transform: translateY(2000px);
}
60% {
-moz-transform: translateY(-30px);
}
80% {
-moz-transform: translateY(10px)
}
100% {
-moz-transform: translateY()
}
}
#-ms-keyframes bounceInUp {
0% {
-ms-transform: translateY(2000px);
}
60% {
-ms-transform: translateY(-30px);
}
80% {
-ms-transform: translateY(10px)
}
100% {
-ms-transform: translateY()
}
}
#-o-keyframes bounceInUp {
0% {
-o-transform: translateY(2000px);
}
60% {
-o-transform: translateY(-30px);
}
80% {
-o-transform: translateY(10px)
}
100% {
-o-transform: translateY()
}
}
#keyframes bounceInUp {
0% {
transform: translateY(2000px);
}
60% {
transform: translateY(-30px);
}
80% {
transform: translateY(10px)
}
100% {
transform: translateY()
}
}
.bounceInUp {
-webkit-animation-name: bounceInUp;
-moz-animation-name: bounceInUp;
-ms-animation-name: bounceInUp;
-o-animation-name: bounceInUp;
animation-name: bounceInUp;
}
JS:
$('#red').click(function(){
$('#red').addClass('active');
$('#red').removeClass('orangeselected');
$('#orange').removeClass('active');
});
$('#orange').click(function(){
$('#orange').addClass('active');
$('#red').removeClass('active');
$('#red').addClass('orangeselected');
});
$('#sidebarhex').fadeTo(0,1);
$('#thecolor').addClass('box animated bounceInDown');
$('.bubble').addClass('box animated bounceInDown');
$('#composeheader').addClass('box animated bounceInDown');
$('#body').addClass('box animated bounceInDown');
setTimeout(function () {
setTimeout(function () {
$('#red').fadeTo(0, 400);
$('#orange').fadeTo(0, 400);
$('#yellow').fadeTo(0, 400);
$('#green').fadeTo(0, 400);
$('#turquoise').fadeTo(0, 400);
$('#blue').fadeTo(0, 400);
$('#purple').fadeTo(0, 400);
$('#gray').fadeTo(0, 400);
}, 400);
$('#red').addClass('box animated bounceInUp');
$('#orange').addClass('box animated bounceInUp');
$('#yellow').addClass('box animated bounceInUp');
$('#green').addClass('box animated bounceInUp');
$('#turquoise').addClass('box animated bounceInUp');
$('#blue').addClass('box animated bounceInUp');
$('#purple').addClass('box animated bounceInUp');
$('#gray').addClass('box animated bounceInUp');
}, 500);
setTimeout(function(){
$('#red').addClass('active');
}, 1050);

Categories