2014-03-01 122 views
0

我有一個Cycle2幻燈片。我希望它每5秒循環一次幻燈片,但我也希望用戶能夠單擊向上或向下鍵來推進幻燈片。點擊向上或向下鍵時,我想確保幻燈片顯示在進入下一個或上一個之前不忙。問題是,當我檢查.cycle-busy時,它每次都返回false。我將幻燈片設置爲暫停狀態,並嘗試檢查。單擊「向上」或「向下」鍵時暫停 - 暫停,並返回false。我錯過了什麼嗎?Cycle2狀態​​始終爲假

我正在使用jquery 1.8.2。

$(document).keydown(function (e) { 
    var busy = $('#mainSlideShow').is('.cycle-busy'); 
    alert(busy); 
    if ($('.cycle-slideshow').is(':animated')) 
     return false; 

    switch (e.which) { 
     case 38: 
      $('.cycle-slideshow').cycle('next'); 
      break; 

     case 40: 
      $('.cycle-slideshow').cycle('prev'); 
      break; 
    } 
}); 

<div id="mainSlideShow" > 
    <div class="cycle-slideshow" 
     data-cycle-timeout="5000" 
     data-cycle-slides="> div" 
     data-cycle-fx="scrollVert" 
     data-cycle-prev=".prev" 
     data-cycle-next=".next" 
     data-cycle-paused="false"> 
     <div class="slide" style="background-image: url('Images/SlideShow/building.jpg');"> 
      <div class="slide-wrapper"> 
       <div class="next"> 
        <img src="Images/prev.png" /> 
       </div> 
       <div class="caption-wrapper"> 
        <div class="caption"> 
         <h2 class="title">Commercial Products</h2> 
         <div class="description"> 
          Specializing in small to mid-size businesses, RAM offers a wide variety of coverages to meet your business needs. 
         </div> 
        </div> 
       </div> 
       <div class="prev"> 
        <img src="Images/next.png" /> 
       </div> 
      </div> 
     </div> 
     <div class="slide" style="background-image: url('Images/SlideShow/farm.jpg');"> 
      <div class="slide-wrapper"> 
       <div class="next"> 
        <img src="Images/prev.png" /> 
       </div> 
       <div class="caption-wrapper"> 
        <div class="caption"> 
         <h2 class="title">Commercial Products</h2> 
         <div class="description"> 
          Specializing in small to mid-size businesses, RAM offers a wide variety of coverages to meet your business needs. 
         </div> 
        </div> 
       </div> 
       <div class="prev"> 
        <img src="Images/next.png" /> 
       </div> 
      </div> 
     </div> 
     <div class="slide" style="background-image: url('Images/SlideShow/family.jpg');"> 
      <div class="slide-wrapper"> 
       <div class="next"> 
        <img src="Images/prev.png" /> 
       </div> 
       <div class="caption-wrapper"> 
        <div class="caption"> 
         <h2 class="title">Commercial Products</h2> 
         <div class="description"> 
          Specializing in small to mid-size businesses, RAM offers a wide variety of coverages to meet your business needs. 
         </div> 
        </div> 
       </div> 
       <div class="prev"> 
        <img src="Images/next.png" /> 
       </div> 
      </div> 
     </div> 
     <div class="slide" style="background-image: url('Images/SlideShow/house.jpg');"> 
      <div class="slide-wrapper"> 
       <div class="next"> 
        <img src="Images/prev.png" /> 
       </div> 
       <div class="caption-wrapper"> 
        <div class="caption"> 
         <h2 class="title">Commercial Products</h2> 
         <div class="description"> 
          Specializing in small to mid-size businesses, RAM offers a wide variety of coverages to meet your business needs. 
         </div> 
        </div> 
       </div> 
       <div class="prev"> 
        <img src="Images/next.png" /> 
       </div> 
      </div> 
     </div> 
    </div> 
</div 

回答

1

的繁忙的值包含在幻燈片的選擇哈希,訪問此值,使用以下方法:

var opts = $('.cycle-slideshow').data('cycle.opts'); 
if(opts.busy){ 
    return false; 
}