2013-11-14 156 views
0

我有兩個語音氣泡每兩秒更改其內容。 我想每次我把鼠標放在氣泡上時,我的changeComment函數就會停下來,這樣用戶將有更多的時間閱讀評論,當鼠標離開氣泡時,函數將重新開始。MouseEnter事件沒有觸發

我有我的演示在這裏:http://jsbin.com/EMogAfud/1

這是我使用

$("bubbleSpeech").mouseenter(function(){ 
    clearInterval(intervalStop); 
}); 

$("bubbleSpeech").mouseleave(function(){ 
    show(); 
    intervalStop=setInterval(show,pause); 
}); 

不明白爲什麼它不工作的功能。我沒有得到事件的火災。

在此先感謝

+4

敢肯定你想使用'$( '#bubbleSpeech')' – AlliterativeAlice

+0

你忘了選擇器前面的'#'嗎? '$( 「#bubbleSpeech」)'。也請發佈相關的html以及你的問題。 – PSL

+0

非常非常非常確定你想這樣做 –

回答

2

你忘了使用 '#':

$("#bubbleSpeech").mouseenter(function(){ 
    clearInterval(intervalStop); 
}); 

$("#bubbleSpeech").mouseleave(function(){ 
    show(); 
    intervalStop=setInterval(show,pause); 
}); 
0

你缺少#

id-selector

$("#bubbleSpeech") 
^ // added # for id-selector 
0

感謝您的意見 他們是兩種方法來做到這一點。

使用jQuery

$("#bubbleSpeech").mouseenter(function(){ 
    clearInterval(intervalStop); 
}); 

$("#bubbleSpeech").mouseleave(function(){ 
    show(); 
    intervalStop=setInterval(show,pause); 
}); 

或者用純JavaScript

演示:http://jsbin.com/ejiFixeG/2

mainSlider=document.getElementById('bubbleSpeech'); 

mainSlider.onmouseenter = function(){ 
    clearTimeout(timerStop) ; 
    clearInterval(intervalStop); 
}; 

mainSlider.onmouseleave = function(){ 
    show(); 
    intervalStop=setInterval(show,pause); 
};