2012-07-30 131 views
2

我正在使用jquery循環,並讓它水平不斷滾動。我希望動畫在用戶懸停時停止。通過插件的「暫停:1」選項,我有這種工作排序,但它不會暫停,直到它已經循環到下一個圖像,這是緩慢的。當用戶懸停時,我希望它暫停中間動畫,因此即使在圖像之間的一半,然後繼續在鼠標懸停。這可能嗎?如何暫停jquery循環插件中間動畫(懸停)

我的代碼:

$('.gallery .continuous').each(function(index, element) { 
    $(element).cycle({ 
     fx:'scrollHorz',     
     continuous: 1, 
     speed:10000, 
     timeout:0, 
     easing: 'linear', 
     pause:1, 
     pauseOnPagerHover: true, 
    }); 
}); 

感謝您的幫助。

+0

只是覺得我會再次檢查,有沒有人有想法如何做到這一點?! – Desmond 2012-07-31 05:31:04

回答

2

嗨德斯蒙德你可以試試這個在你的JavaScript。把它放在文檔中準備好

$('.gallery .continuous').hover(
function(){ 
$(this).cycle('pause'); //Pauses the cycle on hover 
}, 
function(){ 
$(this).cycle('resume'); // Resumes the cycle when mouse is outside div 
}); 

我希望它能爲你工作。

+0

感謝您的幫助Paritosh! – Desmond 2012-11-10 02:39:02

+0

它適合你嗎? – 2012-11-10 17:40:13

+0

你好Paritosh,不,實際上並沒有工作! – Desmond 2012-11-11 22:17:04

-1
<div id="slider"> 
     <img class="images" src="1.jpg"> 
     <img class="images" src="2.jpg"> 
     <img class="images" src="3.jpg"> 
     <img class="images" src="4.jpg"> 
    </div> 

<!-- for example above mentioned is your html with container with id "slider" 

then cycle code will be like that --> 


    <script> 
    //this is your cycling code!!!!!!!!!!!!!!! 
     $('#slider').cycle({ 
     fx:  'scrollHorz', 
     timeout: 200, 
     speed: 1000, 
     next: '.right', 
     prev: '.left' 
    }); 

//if you want to pause you need to use .cycle("pause") for e.g: 

//on mouseover. 

     $('#slider').mouseover(function(){ 
      $('#slider').cycle('pause'); 
     }); 


    //and continue on mouse out 

     $('#slider').mouseout(function(){ 
      $('#slider').cycle('resume'); 
     }); 

    </script> 
+0

歡迎來到Stack Overflow!請不要在多個問題上發佈相同的答案。發佈一個很好的答案,然後投票/標記以重複關閉其他問題。如果問題不是重複的,*定製你對問題的回答。* – 2017-07-31 21:32:20

+1

嘿,歡迎來到Stack Overflow!我想建議您不要粘貼整個代碼,只需鍵入一個答案並顯示代碼並解釋它! – duper51 2017-07-31 21:36:21