2016-11-18 96 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