我创建了一个非常基本的图像滑块,可以在点击div时更改图像(代码如下)。我想将其设置为每5秒自动进行一次。看看其他帖子,似乎我可以用window.setInterval(event, 5000);
做些事情,然后让事件每隔5秒触发一次下一个div。不过,我在设置每个功能时遇到了一些麻烦。我的代码是下面,我希望得到任何帮助:如何让jQuery通过点击每隔几秒钟循环?
HTML:
<div id="slider">
<div id="slider-images">
<img class="1" src="assets/slider-1.jpg" width="613" height="344">
<img class="2" src="assets/slider-2.jpg" width="613" height="344">
<img class="3" src="assets/slider-3.jpg" width="613" height="344">
<img class="4" src="assets/slider-4.jpg" width="613" height="344">
<img class="5" src="assets/slider-5.jpg" width="613" height="344">
<img class="6" src="assets/slider-6.jpg" width="613" height="344">
</div>
<div id="slider-nav">
<div class="description" id="1">
<h1>Heading 1</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="description" id="2">
<h1>Heading 2</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="description" id="3">
<h1>Heading 3</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="description" id="4">
<h1>Heading 4</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="description" id="5">
<h1>Heading 5</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="description" id="6">
<h1>Heading 6</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
的jQuery:
$(function() {
//homepage slider
$('#slider-nav div:first').addClass('current');
$('#slider-images img').hide();
$('#slider-images img:first').addClass('current').show();
$('#slider-nav div').click(function(){
var id = $(this).attr('id');
var sliderImg = "#slider-images img";
$(sliderImg).removeClass('current');
$(sliderImg).fadeOut('slow');
$(sliderImg + "." + id).fadeIn('slow');
$("#slider-nav div").removeClass('current');
$(this).addClass('current');
return false;
});
});
嗯,这似乎没有工作,但我认为它非常接近。我认为他们的语法可能有些问题。任何人更熟练他们我能够发现什么是错的? – Andrew 2011-02-16 18:26:02