I am looking to create an infinite loop that adds a class to each div with a timeout in between.
Currently, I have implemented it like this:
$(document).ready(function() {
$('.small-bordered-box').each(function(i) {
var $t = $(this);
setTimeout(function() {
$t.addClass('active');
}, 2000 * i);
});
});
.small-bordered-box {
display: block;
height: 118px;
width: 100px;
border: 2px solid #3e3b38;
border-radius: 5px;
float: left;
margin-right: 35px;
}
.small-bordered-box.active {
animation: shake 0.83s cubic-bezier(.36, .07, .19, .97) both;
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
perspective: 1000px;
}
@keyframes shake {
10%,
90% {
transform: translate3d(-1px, 0, 0);
}
20%,
80% {
transform: translate3d(2px, 0, 0);
}
30%,
50%,
70% {
transform: translate3d(-4px, 0, 0);
}
40%,
60% {
transform: translate3d(4px, 0, 0);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="small-bordered-box ">
<a href="#">test1</a>
</div>
<div class="small-bordered-box ">
<a href="#">test2</a>
</div>
<div class="small-bordered-box ">
<a href="#">test3</a>
</div>
I want to maintain the same effect but have it loop infinitely so that users always see this animation no matter where they are on the page.