Javascript 使用jQuery每隔15秒添加/删除一个类,并在悬停时停止。

Javascript 使用jQuery每隔15秒添加/删除一个类,并在悬停时停止。,javascript,jquery,html,Javascript,Jquery,Html,我不太擅长jQuery,我在这里被难住了,我正在尝试制作一个jQuery旋转木马,它基本上每15秒自动旋转一次,并在悬停时停止 现在,我为HTML提供了以下内容: <section id="featured"> <div id="hero"> <div class="slide" style="background-image: url(/wp-content/uploads/2016/02/rsz_shutterstock_323582282

我不太擅长jQuery,我在这里被难住了,我正在尝试制作一个jQuery旋转木马,它基本上每15秒自动旋转一次,并在悬停时停止

现在,我为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>
目前在悬停它添加“当前”在两个地方和停止,这是好的,但我想让它自动这样做每10秒


我做错了什么?:)

如果我没弄错,试试这个:

添加以下内容:
var loopCarousel=true

绑定悬停时,将loopCarousel设置为false,不悬停时再次将其设置为true。将此函数添加到javascript中,并用显示的元素替换“your_selector”

function start(counter){
  if(counter < 10000 && loopCarousel){
    setTimeout(function(){
      counter++;

      $("your_selector").mouseover();

      start(counter);
    }, 10000);
  }
}
start(0);
功能启动(计数器){
如果(计数器<10000&&loopCarousel){
setTimeout(函数(){
计数器++;
$(“您的_选择器”).mouseover();
启动(计数器);
}, 10000);
}
}
启动(0);

你在哪里试着设置计时器?还没到那一步。我熟悉这样做的想法--setInterval(function(){///stuff},5000);但不确定如何使它正确地循环子元素。请查看setInterval。很可能。动画嗯,我确实明白了,我试过这么做,但似乎只是把它添加到所有的动画中,然后,把它拿走——这是我不明白的循环部分。我需要它一次向每个元素添加一次电流,然后将其删除。除非我搞砸了,否则它看起来像是每10秒在所有元素上添加电流,然后带走电流——这也是我用它实现的。我需要它把它添加到一个,把它拿走,添加到下一个,重复。Quote“当前悬停它在两个地方都添加了“当前”这是因为你使用的选择器返回多个对象而不是一个$(#latest a)将返回id为“latest”的div下的所有内容。也许用整个代码编写一个JSFiddle以使其更易于理解是个好主意。
function start(counter){
  if(counter < 10000 && loopCarousel){
    setTimeout(function(){
      counter++;

      $("your_selector").mouseover();

      start(counter);
    }, 10000);
  }
}
start(0);