I have css animation that are set on an interval to show themselves and preform when a certain time has passed. It works perfectly when you are on the website however, when you leave the website and open a new tab and come back after a couple seconds, the animation seems to restart and all the circles start all at once.
For my question, I am asking how do you set the circles to restart when the user opens a new tab and come back. Just open the codepen I will have below, open a new tab, and come back after a couple seconds and you will see the circles start all together. My code will be posted below.
jQuery
$("#secondCircle").hide();
setInterval(function() {
$("#secondCircle").show();
$("#secondCircle").css("background-image", "linear-gradient(to top, #feada6 0%, #f5efef 100%)");
},3400);
$("#thirdCircle").hide();
setInterval(function() {
$("#thirdCircle").show();
$("#thirdCircle").css("background-image", "linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%)");
},7430);
$("#fourthCircle").hide();
setInterval(function() {
$("#fourthCircle").show();
$("#fourthCircle").css("background-color", "#fd3061");
},11640);
$("#fifthCircle").hide();
setInterval(function() {
$("#fifthCircle").show();
$("#fifthCircle").css("background-image", "linear-gradient(to top, #cc208e 0%, #6713d2 100%)");
},14000);
$("#sixthCircle").hide();
setInterval(function() {
$("#sixthCircle").show();
$("#sixthCircle").css("background-image", "linear-gradient(to top, #b224ef 0%, #7579ff 100%)");
},20000);
CSS
.bubbles{
position: absolute;
z-index:0;
transform:translateZ(0);
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
-moz-transform: translateZ(0);
-o-transform: translateZ(0);
}
.bubbles li{
position: absolute;
list-style: none;
display: block;
border-radius: 100%;
animation: fadeAndScale 33s ease-in infinite;
-ms-animation: fadeAndScale 33s ease-in infinite;
-webkit-animation: fadeAndScale 26s ease-in infinite;
-moz-animation: fadeAndScale 33s ease-in infinite;
-o-animation: fadeAndScale 33s ease-in infinite;
transition-timing-function: linear;
}
/* The first Circle animation------------------------------------------------------------------------------------------------ */
.bubbles li:nth-child(1) {
width: 1100px;
height: 1100px;
position: relative;
bottom:500px;
left: 400px;
background-image: -webkit-linear-gradient(45deg, #93a5cf 0%, #e4efe9 100%);
background-image: linear-gradient(45deg, #93a5cf 0%, #e4efe9 100%);
animation-name: firstCircle;
}
/* Mozilla First Circle Animation */
@keyframes firstCircle {
0% {
z-index: 100;
transform: scale(0);
}
100%{
z-index: 0;
transform: scale(50);
}
}
@-moz-keyframes firstCircle {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
/* Webkit First Circle Animation */
@-webkit-keyframes firstCircle {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
@-ms-keyframes firstCircle {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes firstCircle {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}
/* End first circle animation -------------------------------------------------------------------------------------- */
/* Begin Second Circle Animation ------------------------------------------------------------------------------------ */
.bubbles li:nth-child(2) {
width: 1100px;
height: 1100px;
position: absolute;
left: 400px;
bottom:200px;
animation-name: secondAnimation;
}
/* Webkit Second Animation */
@-webkit-keyframes secondAnimation {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
/* Mozilla Second Animation */
@-moz-keyframes secondAnimation {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
/* Ms Second Animation */
@-ms-keyframes secondAnimation {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes secondAnimation {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}
/* End of Second Circle ------------------------------------------------------------------------------------- */
/*Begin of Third Circle ----------------------------------------------------------------------------------- */
.bubbles li:nth-child(3) {
width: 1100px;
height: 1100px;
position: absolute;
left: 600px;
bottom:320px;
animation-name: thirdAnimation;
}
/* Webkit Third Animation */
@-webkit-keyframes thirdAnimation {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
/* Mozilla Third Animation */
@-moz-keyframes thirdAnimation {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
/* MS Third Animation */
@-ms-keyframes thirdAnimation {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes thirdAnimation {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}
/* End of the Third Circle --------------------------------------------------------------------------------------------------------- */
/* Begin of Fourth Circle Animation ----------------------------------------------------------------------------------------------- */
.bubbles li:nth-child(4) {
width: 1100px;
height: 1100px;
position: absolute;
left: 100px;
bottom:180px;
animation-name: fourthAnimation;
}
/* Webkit Fourth Animation */
@-webkit-keyframes fourthAnimation {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
/* Mozilla Fourth Animation */
@-moz-keyframes fourthAnimation {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
/* MS Fourth Animation */
@-ms-keyframes fourthAnimation {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes fourthAnimation {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}
/* END of Fourth Animation ------------------------------------------------------------------------------------------------ */
/* Start of Fifth Animation -------------------------------------------------------------------------------------------------- */
.bubbles li:nth-child(5) {
width: 1100px;
height: 1100px;
position: absolute;
left: 500px;
bottom:200px;
animation-name: fifthAnimation;
}
/* Webki Fifth Animation */
@-webkit-keyframes fifthAnimation {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
@-moz-keyframes fifthAnimation {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
@-ms-keyframes fifthAnimation {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes fifthAnimation {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}
/* End of the Fith Circle ----------------------------------------------------------------------------------------------------- */
/* Start of the Sixth Circle ------------------------------------------------------------------------------------------------- */
.bubbles li:nth-child(6) {
width: 1100px;
height: 1100px;
position: absolute;
left: 700px;
bottom:150px;
animation-name: sixthAnimation;
}
/* Webkit sixth animation */
@-webkit-keyframes sixthAnimation {
0% {
z-index: 100;
-webkit-transform: scale(0);
}
100%{
z-index: 0;
-webkit-transform: scale(50);
}
}
/* Mozilla Sixth Animation */
@-moz-keyframes sixthAnimation {
0% {
z-index: 100;
-moz-transform: scale(0);
}
100%{
z-index: 0;
-moz-transform: scale(50);
}
}
/* MS Sixth Animation */
@-ms-keyframes sixthAnimation {
0% {
z-index: 100;
-ms-transform: scale(0);
}
100%{
z-index: 0;
-ms-transform: scale(50);
}
}
@-o-keyframes sixthAnimation {
0% {
z-index: 100;
-o-transform: scale(0);
}
100%{
z-index: 0;
-o-transform: scale(50);
}
}