我對jQuery並不擅長,我在這裏難住,我試圖製作一個基本上每15秒自動旋轉一次並停止懸停的jQuery旋轉木馬。添加/刪除類每15秒使用jQuery並停止懸停。
現在我有這樣的HTML:
<section id="featured">
<div id="hero">
<div class="slide" style="background-image: url(/wp-content/uploads/2016/02/rsz_shutterstock_323582282.jpg)"></div>
<div class="slide" style="background-image: url(/wp-content/uploads/2016/01/rsz_shutterstock_246059269.jpg)"></div>
<div class="slide" style="background-image: url(/wp-content/uploads/2016/01/rsz_shutterstock_342971345.jpg)"></div>
<div class="slide" style="background-image: url(/wp-content/uploads/2016/01/rsz_shutterstock_327686162.jpg)"></div>
</div>
<div class="wrap clearfix" id="latest-wrap">
<div class="clearfix" id="latest">
<h5 id="the-latest"><span>Hot This Week</span></h5>
<a href="/get-all-nine-quicktips-here/" class="">
<article class="featured-article clearfix">
<h4><span class="fa finance-101"></span>finance-101</h4>
<h2 class="featured-title">Our Best Financial Tips to Watch On The Go</h2>
</article>
</a>
<a href="/how-to-throw-the-perfect-wedding-shower/" class="">
<article class="featured-article clearfix">
<h4><span class="fa fun"></span>fun</h4>
<h2 class="featured-title">How to Throw the Perfect Bridal Shower</h2>
</article>
</a>
<a href="/watch-the-full-series-of-ytf-with-dennis-kneale/" class="">
<article class="featured-article clearfix">
<h4><span class="fa finance-101"></span>finance-101</h4>
<h2 class="featured-title">If You're Reading This It's Not Too Late</h2>
</article>
</a>
<a href="/watch-the-full-season-of-mr-and-mrs-adventure-here/" class="">
<article class="featured-article clearfix">
<h4><span class="fa motivation"></span>motivation</h4>
<h2 class="featured-title">Watch One Couple Travel the World on $1k a Month</h2>
</article>
</a>
</div>
</div>
</section>
這裏是我的jQuery ...
$("li.categories").click(function(){
window.location = $(this).find("a").attr("href");
});
$("#featured #hero .slide").eq(0).addClass("current");
$("#latest a").eq(0).addClass("current");
$("#latest a").hover(function(){
$(this).addClass("current");
$("#featured #hero .slide.current").removeClass("current");
$("#featured #hero .slide").eq($("#latest a.current").index()-1).addClass("current");
}, function(){
$(this).removeClass("current");
});
目前懸停它增加了在這兩個地方和停止,「當前」這很好,但是,我希望它每10秒自動執行一次。
我在做什麼錯? :)
你在哪裏嘗試設置計時器? –
還沒有那麼遠。 我熟悉做 - setInterval(function(){ /// stuff },5000); 但不知道如何使它正確地循環通過子元素。 –
看看setInterval。 http://www.w3schools.com/jsref/met_win_setinterval.asp和可能。動畫 – StealthSpoder