2012-12-17 95 views
4

嗨我是一個相對較新的使用jQuery卷軸。當您將鼠標懸停在jQuery卷軸http://test.vostrel.cz/jquery.reel/docs/jquery.reel.html上時,我想知道如何停止並播放。我看到有停止,開始和暫停事件,但我不確定如何在懸停時激活它。停止/播放懸停jquery卷軸

謝謝!

<img id="image360" src='1.jpg' width="610" height="480" /> 

<script> 
$(function(){ 

//pause on hover (This does not work although hover is registered) 
     $('#image360').hover(function() { 

     ('#image360').pause(); 
}, 

function() { 
     ('#image360').play(); 
}); 

//360 settings 

     $('#image360').reel({ 
     indicator: 5, 
     cw:   true, 
     frame:  36, 
     speed:  -0.3, 
     velocity: 2, 
     brake:  .2, 
     images:  'cmopen/#.jpg' 
     }); 

     }); 
</script> 
+0

你能顯示一些代碼嗎?你已經嘗試了什麼?另見:http://www.stackoverflow.com/questions/how-to-ask – Spontifixus

+0

非常感謝幫助,更新了代碼。 – davidinblack

回答

0

您必須使用方法:pause(),play()。

$(<your_element>).hover(function() { 
    <your_reel>.pause(); 
},function() { 
    <your_reel>.play(); 
}); 
1

我有完全相同的問題,有兩個JS功能解決了這個問題:

function reel_pause() { 
    $('#your_reel_id').trigger("stop"); //stoppe le défilement automatique. 
} 
function reel_play() { 
    if ($('#your_reel_id').data("backwards")) { //teste le sens de défilement. 
     $('#your_reel_id').trigger('play'); //relance le défilement à la même frame où on l'a arrêté. Attention, il relance dans son sens naturel (droite à gauche). 
     $('#your_reel_id').data("backwards", true) //inverse le sens de défilement 
    } else { 
     $('#your_reel_id').trigger('play'); //si le sens où l'on a arrêté le défilement est le sens naturel, on n'a pas besoin d'inverser comme au dessus. 
    } 
} 

如果你不想你的卷軸循環,只有重要的: 的「if」語句,如果您不說法語,則用於檢查卷軸播放時的方向。

$('#your_reel_id').data("backwards") 
$('#your_reel_id').data("backwards", true) 

第一個返回true或false。虛假 - >從右向左播放。 第二個改變自然方向 - >從左到右。 我這樣做是因爲當您彈奏卷軸時,它會以自然方向播放。即使你在以其他方式演奏時停下來。

的HTML如下:

<div id="container" onmouseover="reel_pause()" onmouseout="reel_play()"> 
    <img src="../Images/image.jpg" id="your_reel_id" width="900" height="500" /> 
</div> 

我把它包裹在一個div因爲我使用的卷軸中的鏈接。如果您將鼠標懸停在某個鏈接上,就好像您將鼠標懸停並重新開始播放。 希望它有幫助!

我不是一個JS專家,所以如果任何人有更好的方法來做到這一點,請張貼它!