I am trying to create a fadein fadeout animation where The individual items are shown for an specific interval on the screen but the gap between the fadeout of active and fadein of next item is different.
So suppose we have a group of images and I want the images to appear on screen for 5 seconds and when a image hides and next image shows I want a variable time difference between each interval.
This is what I have tried but its not working like the way I need it
<script>
var myVar = setInterval(function(){myTimer()}, 5000);
function myTimer() {
var $active = $('#cycler .active');
var $next = ($active.next().length > 0) ? $active.next() : $('#cycler img:first');
$active.fadeOut().removeClass('active');
$next.delay(getRandomArbitary(5,20)*1000).fadeIn().addClass('active');
}
function getRandomArbitary (min, max) {
return Math.random() * (max - min) + min;
}
</script>
<style>
#cycler{position:relative;}
#cycler img{position:absolute;display:none; max-width:250px;}
#cycler img.active{z-index:3; display:block;}
</style>
<div id="cycler">
<img src="images/p1.jpg" class="active">
<img src="images/p2.jpg">
<img src="images/p3.jpg">
<img src="images/p4.jpg">
</div>
Here is the fiddle