Some issues with your code
fadeIn can take as parameters duration, easing and a callback function
So passing li
does not do anything ..
You can use the callback to initiate the animation of the next li
in line ..
like so
function InOut( elem )
{
elem.delay()
.fadeIn()
.delay()
.fadeOut(
function(){ InOut( elem.next() ); }
);
}
and the first time just do
$('#content li').hide();
InOut( $('#content li:first') );
Demo :
// http://www.jsfiddle.net/gaby/S5Cjm/
function InOut(elem) {
elem.delay()
.fadeIn()
.delay()
.fadeOut(
function() {
InOut(elem.next());
}
);
}
$(function() {
$('#content li').hide();
InOut($('#content li:first'));
});
<!-- http://www.jsfiddle.net/gaby/S5Cjm/ -->
<ul id="content">
<li>first</li>
<li>second</li>
<li>third</li>
<li>fourth</li>
<li>fifth</li>
<li>sixth</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
If you want the loop to go on forever then change the fadeOut
with the callback to
.fadeOut(
function(){
if(elem.next().length > 0) // if there is a next element
{InOut( elem.next() );} // use it
else
{InOut( elem.siblings(':first'));} // if not, then use go back to the first sibling
}
);
Demo:
// http://www.jsfiddle.net/gaby/S5Cjm/1/
function InOut(elem) {
elem.delay()
.fadeIn()
.delay()
.fadeOut(
function() {
if (elem.next().length > 0) {
InOut(elem.next());
} else {
InOut(elem.siblings(':first'));
}
}
);
}
$(function() {
$('#content li').hide();
InOut($('#content li:first'));
});
<!-- http://www.jsfiddle.net/gaby/S5Cjm/1/ -->
<ul id="content">
<li>first</li>
<li>second</li>
<li>third</li>
<li>fourth</li>
<li>fifth</li>
<li>sixth</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>