What I want
I am trying to create animation using fadeIn()/fadOut()
function in jQuery, I completed animation but It's working for one time only, although I want it to repeat for multiple times
What I tried
I tried to do this using setInterval() function twice time, where I added duration of total time of animation using totalDur variable, and passed it to parent level setInterval function
Here what I did, Please check this
$(document).ready(function() {
//this is for repeat again
setInterval(function() {
$('.box').each(function(index) {
//this is for each box animation
setInterval(function(eachshowdiv) {
eachshowdiv.fadeIn();
}, index * 800, $(this));
});
}, 2000);
});
.wrapper {
width: 1000px;
margin: 0px auto;
}
.wrapper .box {
height: 250px;
width: 18%;
margin-right: 2%;
float: left;
background: green;
display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
You can use
.promise()
,.fadeOut()
, recursionTo reverse the animation at completion you can use
.queue()
,.delay()
,.promise()
,.then()
,.toArray()
,Array.prototype.reverse()
,.animate()
to animateopacity
of the elements.