鼠标输入事件未触发

MouseEnter event is not firing

本文关键字:入事件 输入 鼠标      更新时间:2023-09-26

我有两个语音气泡每两秒更改一次内容。我尝试每次将鼠标放在气泡上时,我的 changeComment 函数都会停止,这样用户将有更多时间阅读注释,当鼠标离开气泡时,该功能将再次启动。

我这里有我的演示:http://jsbin.com/EMogAfud/1

这是我正在使用的功能

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

不太确定为什么它不起作用。我没有收到事件火灾。

提前致谢

你忘了使用'#' :

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

你缺少#

标识选择器

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

感谢您的评论它们是执行此操作的两种方法。

使用 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);
};