javascript - Add/Remove a Class Every 15 seconds using jQuery and stop on hover. -
i'm not great @ jquery , i'm stumped here, i'm trying make jquery carousel rotates every 15 seconds automatically , stops on hover.
right have 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 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 watch on 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 throw 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 it's not 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 1 couple travel world on $1k month</h2> </article> </a> </div> </div> </section>
here's have 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"); });
currently on hover adds "current" in both places , stops , that's fine, but, i'd automatically every 10 seconds.
what doing wrong? :)
if got right, try this:
add this: var loopcarousel = true;
when binding hover, set loopcarousel false, set true again when not hovering. add function javascript , replace "your_selector" element being displayed.
function start(counter){ if(counter < 10000 && loopcarousel){ settimeout(function(){ counter++; $("your_selector").mouseover(); start(counter); }, 10000); } } start(0);
Comments
Post a Comment