2013-01-08 60 views
0

我已經成立了一個例子一個超級簡單的功能轉盤這裏:懸停暫停簡單的jQuery旋轉木馬

http://codepen.io/anon/full/myvAz

的問題是,我不能讓傳送帶停止在懸停旋轉。

即使它有一個設置的寬度和高度,我甚至不能在包含div的盤旋時觸發警報。 但是,如果我將懸停部分粘貼到控制檯中,我可以獲得警報。

它與其他代碼結合時似乎不會觸發。

任何幫助將感激地讚賞

感謝

繼承人的代碼:

<script> 
// Main image carousel 
$(document).ready(function(){ 
$("#headerMrS > div:gt(0)").hide(); 

var carouDiv = function(){ 
    setInterval(function() { 
     $('#headerMrS > div:first') 
     .fadeOut(500) 
     .next() 
     .fadeIn(500) 
     .end() 
     .appendTo('#headerMrS'); 
    }, 2000); 
}; 

$(carouDiv());//Initialise the carousel function 

$("#headerMrS").hover(function(){//Stop the carousel on hover 
$(this).stop; 
    },function(){ 
    $(this).resume; 
}); 


//Direction Arrow links 
$(".button-sales").click(function(){ 
    $(".header").fadeOut(800); 
    $(".sales").animate({opacity:"show"},800); 
}); 
$(".button-modern").click(function(){ 
    $(".header").fadeOut(800); 
    $(".modern").animate({opacity:"show"},800); 
}); 
$(".button-antique").click(function(){ 
    $(".header").fadeOut(800); 
    $(".antique").animate({opacity:"show"},800); 
}); 
}); 

<style> 

#headerMrS {position:relative; height:150px; width:350px} 
.header {position:absolute; top:0; left:0} 
</style> 

<div id="headerMrS"> 
<div class="header sales active"> 
    <div class="header-content"> 
     <img src="http://placehold.it/350x150/4787ed/ffffff" alt="" /> 
     <div class="button-next button-antique">next</div> 
     <div class="button-prev button-modern">prev</div> 
    </div> 
</div> 
<div class="header antique"> 
    <div class="header-content"> 
     <img src="http://placehold.it/350x150/fc8a41/ffffff" alt="" /> 

     <div class="button-next button-modern">next</div> 
     <div class="button-prev button-sales">prev</div> 
    </div> 
</div> 
<div class="header modern"> 
    <div class="header-content"> 
     <img src="http://placehold.it/350x150/e7376b/ffffff" alt="" /> 

     <div class="button-next button-sales">next</div> 
     <div class="button-prev button-antique">prev</div> 
    </div> 
</div> 
+1

哪個代碼?我只能在這裏看到一個鏈接... –

回答

2

怎麼樣使用clearInterval()

而不是簡單地調用setInterval(),將setInterval()函數分配給一個變量,下面我使用carouselInt。這對於撥打clearInterval()是必要的。 要停止時間間隔,您可以致電clearInterval(carouselInt)

從我剛剛閱讀的文件中,stop()將停止當前動畫,但每2秒鐘會有一個新動畫。它對引發動畫觸發的setInterval沒有明顯的影響。

您可以嘗試以下操作。

var carouselInt = ''; 

var carouDiv = function(){ 
    carouselInt = setInterval(function() { 
     $('#headerMrS > div:first') 
     .fadeOut(500) 
     .next() 
     .fadeIn(500) 
     .end() 
     .appendTo('#headerMrS'); 
    }, 2000); 
}; 

$(carouDiv());//Initialise the carousel function 

$("#headerMrS").hover(function(){//Stop the carousel on hover 
clearInterval(carouselInt); 
    },function(){ 
    carouDiv(); 
}); 
+0

哇,謝謝,似乎工作的一種享受!我嘗試使用setInterval,但沒有運氣..關於你已經通過clearInterval一個匿名變量的方式已經解決了這個權利嗎? – h0rhay

+0

您分配setInterval函數爲va riable,並在需要時將該變量傳遞給clearInterval函數。我編輯了我的答案以澄清。 – daveyfaherty

+0

傳奇!乾杯隊友 – h0rhay

0

好像你身邊的63線未閉合的腳本標記你HTML - 這可能是問題嗎?

+0

你確定嗎?我看不出它..這一切看起來關閉OK – h0rhay

+0

同意,' 未捕獲的語法錯誤:意外的標記<

  • 11. 將循環速度設置爲懸停時的旋轉木馬
  • 12. 旋轉木馬替換鼠標懸停上的圖像
  • 13. css拇指旋轉木馬停在0
  • 14. 暫停jquery中的懸停
  • 15. jquery旋轉木馬
  • 16. 使Bootstrap旋轉木馬導航僅在懸停時顯示
  • 17. 暫停jQuery懸停(鼠標懸停)
  • 18. 暫停懸停動畫懸停Jquery
  • 19. 旋轉木馬內的旋轉木馬
  • 20. jQuery圖像旋轉懸停
  • 21. jquery暫停懸停滑塊
  • 22. jquery滑塊暫停懸停
  • 23. 添加暫停懸停jQuery
  • 24. 將暫停按鈕添加到jQuery Twitter Bootstrap垂直選項卡旋轉木馬
  • 25. 停止旋轉圖像暫停時懸停在其上
  • 26. 引導旋轉木馬:旋轉木馬
  • 27. 停止Vimeo的嵌入jQuery的無限旋轉木馬
  • 28. jQuery的3D旋轉木馬
  • 29. 停止jquery動畫。建立一個旋轉木馬
  • 30. jQuery旋轉木馬滑塊