I've got a unique little CodePen with an animation that I want to execute only if the user hasn't clicked on the <div class="someDiv">
for 30 seconds.
My question is, can someone guide me in the right direction so that when someone doesn't click on:
<div class="someDiv">
</div>
...for 30 seconds, this CSS will be applied (ONCE) by appending an id, similar to
$(".someDiv").attr("id", "#theBounce");
and removing it in a reverse manner.
#theBounce {
background-color:red;
width:50px;
height:50px;
margin-left:auto;
margin-right:auto;
margin-top:5%;
-moz-animation: bounce 1.5s infinite;
-webkit-animation: bounce 1.5s infinite;
animation: bounce 1.5s infinite;
}
@-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
transform: translateY(-15px);
}
}
@-webkit-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
-ms-transform: translateY(-30px);
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
-ms-transform: translateY(-15px);
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}
This means that a click will reset the script's counter, and not clicking for 30 seconds will apply the CSS for at least 1.5 seconds, then remove it, and start the timer again. I'm struggling to get this to work, especially the timing/reset on click part.
A link, an idea, a suggestion. Any help is appreciated. Thank you.