i have a simple slideshow which is working okay so far. it consists of a pager and the images to display. both are an unordered list:
<ul id="keyvisualpager">
<li><a><span>Show Keyvisual 1</span></a></li>
<li><a><span>Show Keyvisual 2</span></a></li>
<li><a><span>Show Keyvisual 3</span></a></li>
</ul>
<ul id="keyvisualslides">
<li><img src="index_files/mbr_keyvisual1.jpg" alt="Keyvisual" /></li>
<li><img src="index_files/mbr_keyvisual2.jpg" alt="Keyvisual" /></li>
<li><img src="index_files/mbr_keyvisual3.jpg" alt="Keyvisual" /></li>
</ul>
The according jQuery code is:
$('#keyvisualpager li a').click(function () {
// get position of a element
var mbr_index = $(this).parent().prevAll().length;
var mbr_targetkeyvisual = mbr_index + 1;
// hide current image and show the target image
$('#keyvisualslides li:visible').hide();
$('#keyvisualslides li:nth-child('+mbr_targetkeyvisual+')').show()
// remove active class from current indicator and add the same class to target indicator
$('#keyvisualpager li a').removeClass('keyvisualactive');
$('#keyvisualpager li:nth-child('+mbr_targetkeyvisual+') a').addClass('keyvisualactive');
});
initially all images are set to display: none; ... upcon clicking a a link in #keyvisualpager the according image is then displayed. at the same time the indicator changes accordingly.
now, my problem:
apart from this mode of navigating through the images i need the whole slideshow to automatically advance. how can i achieve that:
a) the next image is shown after lets say 5 seconds and
b) the class ".keyvisualactive" is added to the according a element in #keyvisualpager
note: unfortunately i have to use jquery 1.2.1, updating is not an option.
thanks for your help guys
EDIT
i am now using this code. it almost works. but after the last image in the set is displayed: how can i tell it to start over with the first image? thanks!
var reload = setInterval(function(){
// get position of a element
var mbr_index = $('#keyvisualpager li .keyvisualactive').parent().prevAll().length;
var mbr_targetkeyvisual = mbr_index + 2;
// alert(mbr_index+'//'+mbr_targetkeyvisual)
// hide current image and show the target image
$('#keyvisualslides li:visible').hide();
$('#keyvisualslides li:nth-child('+mbr_targetkeyvisual+')').show();
// remove active class from current indicator and add the same class to target indicator
$('#keyvisualpager li a').removeClass('keyvisualactive');
$('#keyvisualpager li:nth-child('+mbr_targetkeyvisual+') a').addClass('keyvisualactive');
}, 2000);