我創建了一個非常基本的圖像滑塊,可以在點擊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