.
, intervals.
, ... !!! ()
interval, 6 timeouts.
setTimeouts , .animateD... z-.
animation-play-state.
, mouseleave timeouts interval, "reset" . interval.
CodePen.
CSS JS:
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%;
transform:scale(20);
z-index:98;
}
.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%);
}
.bubbles li:nth-child(2) {
width: 1100px;
height: 1100px;
position: absolute;
left: 400px;
bottom:200px;
background-image: -webkit-linear-gradient(to top, #feada6 0%, #f5efef 100%);
background-image: linear-gradient(to top, #feada6 0%, #f5efef 100%);
}
.bubbles li:nth-child(3) {
width: 1100px;
height: 1100px;
position: absolute;
left: 600px;
bottom:320px;
background-image: -webkit-linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%);
background-image: linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%);
}
.bubbles li:nth-child(4) {
width: 1100px;
height: 1100px;
position: absolute;
left: 100px;
bottom:180px;
background-color: #fd3061;
}
.bubbles li:nth-child(5) {
width: 1100px;
height: 1100px;
position: absolute;
left: 500px;
bottom:200px;
background-image: -webkit-linear-gradient(to top, #cc208e 0%, #6713d2 100%);
background-image: linear-gradient(to top, #cc208e 0%, #6713d2 100%);
}
.bubbles li:nth-child(6) {
width: 1100px;
height: 1100px;
position: absolute;
left: 700px;
bottom:150px;
background-image: -webkit-linear-gradient(to top, #b224ef 0%, #7579ff 100%);
background-image: linear-gradient(to top, #b224ef 0%, #7579ff 100%);
}
.animateD{
animation-name: CircleCSSAnimation;
animation-duration: 5.2s;
animation-iteration-count: infinite;
}
@keyframes CircleCSSAnimation {
0% { transform: scale(0); }
6% { transform: scale(0); }
99%{ transform: scale(4); }
100%{ transform: scale(4); }
}
@-moz-keyframes CircleCSSAnimation {
0% { -moz-transform: scale(0); }
6% { -moz-transform: scale(0); }
99%{ -moz-transform: scale(4); }
100%{ -moz-transform: scale(4); }
}
@-webkit-keyframes CircleCSSAnimation {
0% { -webkit-transform: scale(0); }
6% { -webkit-transform: scale(0); }
99%{ -webkit-transform: scale(4); }
100%{ -webkit-transform: scale(4); }
}
@-ms-keyframes CircleCSSAnimation {
0% { -ms-transform: scale(0); }
6% { -ms-transform: scale(0); }
99%{ -ms-transform: scale(4); }
100%{ -ms-transform: scale(4); }
}
@-o-keyframes CircleCSSAnimation {
0% { -o-transform: scale(0); }
6% { -o-transform: scale(0); }
99%{ -o-transform: scale(10); }
100%{ -o-transform: scale(10); }
}
JS:
var timeout2;
var timeout3;
var timeout4;
var timeout5;
var timeout6;
var intervalsSetting = function(num){
console.log("SETTING");
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(5).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(0).addClass("animateD").css({"z-index":100});
console.log("1");
timeout2 = setTimeout(function(){
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(0).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(1).addClass("animateD").css({"z-index":100});
console.log("2");
},5000);
timeout3 = setTimeout(function(){
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(1).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(2).addClass("animateD").css({"z-index":100});
console.log("3");
},10000);
timeout4 = setTimeout(function(){
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(2).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(3).addClass("animateD").css({"z-index":100});
console.log("4");
},15000);
timeout5 = setTimeout(function(){
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(3).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(4).addClass("animateD").css({"z-index":100});
console.log("5");
},20000);
timeout6 = setTimeout(function(){
$(".bubbles li").css({"z-index":0});
$(".bubbles li").eq(4).removeClass("animateD").css({"z-index":99});
$(".bubbles li").eq(5).addClass("animateD").css({"z-index":100});
console.log("6");
},25000);
};
intervalsSetting();
var myInterval = setInterval(function(){
intervalsSetting();
},30000);
var mouseISin=true;
$("body").on("mouseleave",function(){
console.log("MOUSE IS OUT");
mouseISin=false;
$(".bubbles li").removeClass("animateD");
clearTimeout(timeout2);
clearTimeout(timeout3);
clearTimeout(timeout4);
clearTimeout(timeout5);
clearTimeout(timeout6);
clearInterval(myInterval);
$(".bubbles li").css({"z-index":0});
});
$("body").on("mouseenter",function(){
if(!mouseISin){
console.log("MOUSE IS IN");
mouseISin=true;
clearInterval(myInterval);
intervalsSetting();
myInterval = setInterval(function(){
intervalsSetting();
},30000);
}
});
...
body.
I think this may be the decisive moment for pausing the animation.
And resume it when the mouse comes back through body.
Codepen
$("body").on("mouseleave",function(){
console.log("MOUSE IS OUT");
$(".bubbles li").css({"animation-play-state":"paused"})
});
$(window).on("mouseenter",function(){
console.log("MOUSE IS IN");
$(".bubbles li").css({"animation-play-state":"running"})
});