2016-11-18 98 views
1

我有一個自舉傳送帶,其進度條填滿並觸發下一張幻燈片。我的問題是,現在旋轉木馬暫停時,我將鼠標懸停在幻燈片上,我希望它不會暫停並繼續前進。試圖阻止自引導傳送帶暫停懸停

這裏是我的代碼:

$(document).ready(function(){ 
    var percent = 0, 
    interval =35//it takes about 6s, interval=20 takes about 4s 
    $bar = $('#progress-bar'), 
    $crsl = $('#carousel-hero'); 
    $('.carousel-indicators li, .carousel-control').click(function(){$bar.css({width:0.5+'%'});}); 
    /*line above just for showing when controls are clicked the bar goes to 0.5% to make more friendly, 
    if you want when clicked set bar empty, change on width:0.5 to width:0*/ 
    $crsl.carousel({//initialize 
     interval: false, 
     pause: false 
    }).on('slide.bs.carousel', function(){percent = 0;});//This event fires immediately when the bootstrap slide instance method is invoked. 
    function progressBarCarousel() { 
     $bar.css({width:percent+'%'}); 
     percent = percent +0.5; 
     if (percent>=100) { 
      percent=0; 
      $crsl.carousel('next'); 
     } 
    } 
    var barInterval = setInterval(progressBarCarousel, interval);//set interval to progressBarCarousel function 
    if (!(/Mobi/.test(navigator.userAgent))) {//tests if it isn't mobile 
     $crsl.hover(function(){ 
        clearInterval(barInterval); 
       }, 
       function(){ 
        barInterval = setInterval(progressBarCarousel, interval); 
       } 
     ); 
    } 
}); 

而我的HTML:

<div id="carousel-hero" class="carousel slide" data-ride="carousel"><!-- Main Slider --> 
       <ol class="carousel-indicators"> 
       <li data-target="#carousel-hero" data-slide-to="0" class="active"></li> 
       <li data-target="#carousel-hero" data-slide-to="1"></li> 
       <li data-target="#carousel-hero" data-slide-to="2"></li> 
       </ol> 
      <div class="carousel-inner"> 
       <div class="item active"><!-- First Slide --> 
        <div class="overlay"></div> 
        <img src="images/hero1.jpg" alt="hero-image" class="img-responsive"> 
        <div class="carousel-caption"><!-- Tagline --> 
         <h1 class="tagline">WE ARE <span class="colored">NIXO</span> CREATIVE</h1> 
         <h5>Branding | Design | Developement</h5> 
        </div> 
       </div>   
       <div class="item"><!-- Second Slide --> 
        <div class="overlay"></div> 
        <img src="images/hero2.jpg" alt="hero-image" class="img-responsive"> 
        <div class="carousel-caption"><!-- Tagline --> 
         <h1 class="tagline">WE <span class="colored">ALWAYS</span> DELIVER</h1> 
         <h5>UX | Marketing | Ideas</h5> 
        </div> 
       </div> 
       <div class="item"><!-- Third Slide --> 
        <div class="overlay"></div> 
        <img src="images/hero3.jpg" alt="hero-image" class="img-responsive"> 
        <div class="carousel-caption"><!-- Tagline --> 
         <h1 class="tagline">WE <span class="colored">LOVE</span> DESIGN</h1> 
         <h5>Beautiful | Clean | Inspiring</h5> 
        </div> 
       </div> 
       <!-- Carousel Controlls --> 
       <a id="hero-control-left" class="control-hero control-left" href="#carousel-hero" role="button" data-slide="prev"> 
        <span class="pe-7s-angle-left pe-4x" aria-hidden="true"></span> 
        <span class="sr-only">Previous</span> 
       </a> 
       <a id="hero-control-right" class="control-hero control-right" href="#carousel-hero" role="button" data-slide="next"> 
        <span class="pe-7s-angle-right pe-4x" aria-hidden="true"></span> 
        <span class="sr-only">Next</span> 
       </a> 
      </div> 
      <div id="progress-bar"></div> <!-- Carousel Progress Bar --> 
    </div> 

事情我已經嘗試:

    在js文件
  • 設置暫停: '無'
  • 向傳送帶添加數據暫停=「假」
  • puase:false和data-pause =「false」同時

任何幫助都是有效的。

+0

暫停選項工作爲我好(通過添加作爲數據屬性或JS)。 – makshh

回答

2

設置暫停爲null,數據暫停=「假」

$crsl.carousel({//initialize 
     interval: false, 
     pause: null 
}) 

<div id="carousel-hero" class="carousel slide" data-ride="carousel" data-pause="null"> 

瞭解更多關於轉盤選擇這裏

https://v4-alpha.getbootstrap.com/components/carousel/#options

爲了避免進度條停止刪除代碼爲CRSL .hover清除進度條的間隔並在模糊時重新啓動它。

工作實施例:https://jsfiddle.net/ne9x9Lp1/

+0

感謝您的答案,但它仍然無法正常工作。我仍然停留在懸停。 – Novakim

+0

它適用於我在Chrome瀏覽器上,在您正在檢查的瀏覽器上。 – Deep

+0

我已經在Chrome,Firefox,Opera,Edge和IE 11上測試過。它發生在所有這些 – Novakim