jQuery - 工具提示 - 鼠标悬停 & mouseout 似乎在没有鼠标移动的情况下循环触发-hoverintent 没有帮助
我想做的事情: 我有一个在页面加载时生成并隐藏的 div。当鼠标悬停在页面上的特定元素上时,我想将 div 显示为元素上方的工具提示。我已将“ToolTipRequired”类添加到页面上需要此功能的所有元素,并在页面加载时绑定悬停意图。
我的代码:
jQuery(document).ready(function () {
jQuery('.ToolTipRequired').each(function () {
jQuery(this).hoverIntent({ over: function (event) {
var toolTip = jQuery('#ToolTipDiv');
// xCoord = (destination - ((toolTip width - 14px padding either side of image) / 2)) + (destination width / 2);
var xCoord = event.pageX - ((toolTip.width() - 28) / 2) - 15;
// yCoord = destination - (toolTip height - 14px padding top and 10px padding bottom)
var yCoord = event.pageY - (toolTip.height() - 25) - 15;
// need to show the tool tip first so that we can set it's offset
toolTip.show('fast');
toolTip.offset({ left: xCoord, top: yCoord });
},
timeout: 500,
out: function () {
jQuery('#ToolTipPanel').hide();
}
});
});
问题: 10% 的时候效果很好,另外 90% 的时候工具提示 div 会闪烁,也就是说,即使鼠标保持静止,它也会无限地隐藏和显示。鼠标悬停和鼠标移出事件似乎在无休止地触发。有人告诉我使用悬停意图可以解决这个问题,但它似乎没有产生任何影响。 有人知道吗?
What I'm trying to do:
I have a div that I generate and hide on page load. When specific elements on the page are moused over, I want to display the div as a tool tip above the element. I had added a 'ToolTipRequired' class to all the elements on the page that require this functionality and am binding hoverintent on page load.
My Code:
jQuery(document).ready(function () {
jQuery('.ToolTipRequired').each(function () {
jQuery(this).hoverIntent({ over: function (event) {
var toolTip = jQuery('#ToolTipDiv');
// xCoord = (destination - ((toolTip width - 14px padding either side of image) / 2)) + (destination width / 2);
var xCoord = event.pageX - ((toolTip.width() - 28) / 2) - 15;
// yCoord = destination - (toolTip height - 14px padding top and 10px padding bottom)
var yCoord = event.pageY - (toolTip.height() - 25) - 15;
// need to show the tool tip first so that we can set it's offset
toolTip.show('fast');
toolTip.offset({ left: xCoord, top: yCoord });
},
timeout: 500,
out: function () {
jQuery('#ToolTipPanel').hide();
}
});
});
Problem:
10% of the time this works beautifully, the other 90% the tool tip div flashes, that is, it hides and shows infinitely even if the mouse remains still. It seems like the mouseover and mouseout events are endlessly firing. I was told the use of hoverintent would rectify this problem but it doesn't seem to have made a difference.
Does anyone have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
mouseenter
和mouseleave
代替,Try using
mouseenter
andmouseleave
instead ,遇到这个问题一次,你可以使用这个:
Got this problem once, you can use this :