mrj*_*hms 1 javascript onmousemove balloon
[edit]所以我使用了下面建议的一个javascript工具提示.如果你搬家的话,我得到了你停下来隐藏的提示.唯一的问题是它在我这样做时有效:
document.onmousemove = (function() {
var onmousestop = function() {
Tip('Click to search here');
document.getElementById('MyDiv').onmousemove = function() {
UnTip();
};
}, thread;
return function() {
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
Run Code Online (Sandbox Code Playgroud)
但我希望该函数仅适用于特定div,如果我将第一行更改为"document.getElementById('MyDiv').onmousemove =(function(){"我得到一个javascript错误document.getElementById('MyDiv' )是null我想念的是什么......?
[/编辑]
当用户鼠标停留在元素上超过1.5秒时,我想显示气球样式消息.然后如果他们移动鼠标我想隐藏气球.我正在尝试使用我发现的一些JavaScript代码.这是我用来检测鼠标何时停止的代码:
document.onmousemove = (function() {
var onmousestop = function() {
//code to show the ballon
};
}, thread;
return function() {
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
Run Code Online (Sandbox Code Playgroud)
所以我有两个问题.一,有没有人有一个推荐的轻量级javascript气球,将显示在光标位置.二,检测鼠标停止代码工作正常,但我很难知道如何检测鼠标已经开始再次移动并隐藏气球.谢谢...
要回答这个问题有点晚了,但这对有需要的人有帮助.
我需要这个功能,能够检测鼠标何时停止移动一段时间,以便在悬停在视频上时隐藏HTML/JS播放器控制器.这是工具提示的修订代码:
document.getElementById('MyDiv').onmousemove = (function() {
var onmousestop = function() {
Tip('Click to search here');
}, thread;
return function() {
UnTip();
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
Run Code Online (Sandbox Code Playgroud)
在我的例子中,我使用了一些jQuery来为我的播放器控制器选择元素:
$('div.video')[0].onmousemove = (function() {
var onmousestop = function() {
$('div.controls').fadeOut('fast');
}, thread;
return function() {
$('div.controls').fadeIn('fast');
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
Run Code Online (Sandbox Code Playgroud)