如果鼠标悬停在元素上一段时间则显示弹出窗口
我想知道当鼠标悬停在某个元素上一段时间时如何显示弹出窗口/提示框,例如伪代码:
if mouseover
if hovered for more than 2 seconds
--> show popup/tipbox
else
---> cancel mouseover
else if mouseout
--> reset timer/cancel mouseover
到目前为止我已经这样做了,但是如果我将鼠标悬停并且它不能有效工作快速移动鼠标,它仍然会显示弹出窗口/提示框。
$('a[rel=tip]').live('mouseover mouseout', function(e)
{
if(e.type == 'mouseover')
{
var mouseTime = setTimeout(function()
{
$('.tipbox').slideDown('fast');
}, 1000);
}
else if(e.type == 'mouseout')
{
if(mouseTime)
{
cancelTimeout(mouseTime);
mouseTime = null;
$('.tipbox').slideUp('fast');
}
}
});
编辑:添加了赏金。
I'm wondering how to show a popup/tipbox when a mouse has been hovered over an element for a period of time, e.g. pseudo code:
if mouseover
if hovered for more than 2 seconds
--> show popup/tipbox
else
---> cancel mouseover
else if mouseout
--> reset timer/cancel mouseover
I've done this so far, but it doesn't work effectively, if I hover and move the mouse quickly, it will still show the popup/tipbox.
$('a[rel=tip]').live('mouseover mouseout', function(e)
{
if(e.type == 'mouseover')
{
var mouseTime = setTimeout(function()
{
$('.tipbox').slideDown('fast');
}, 1000);
}
else if(e.type == 'mouseout')
{
if(mouseTime)
{
cancelTimeout(mouseTime);
mouseTime = null;
$('.tipbox').slideUp('fast');
}
}
});
EDIT: Bounty added.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎对我有用:
HTML
JS
<强>CSS
This seems to work for me:
HTML
JS
CSS
试试这个:
html 代码应该是:
Try this:
And the html code should be:
你可以尝试 这个插件 - 它是由一本非常好的 jQuery 书籍的作者之一编写的,所以应该不错。这些演示看起来很有希望。
You could try This plugin - it's written by one of the authors of a very good jQuery book, so ought to be good. The demos look promising.