Javascript 检测静止光标是否悬停在以前隐藏的、现在可见的元素上 说明:
作为我上一个问题的继续(或者重新表述),我试图检测光标是否位于以前隐藏、现在已淡入元素的上方,而不实际移动光标 设置如下:当一个元素消失在鼠标下方时,让鼠标完全静止。淡入动画完成后,脚本应检测到新显示的元素实际上位于光标下方,然后通过Javascript 检测静止光标是否悬停在以前隐藏的、现在可见的元素上 说明:,javascript,jquery,html,css,mouseevent,Javascript,Jquery,Html,Css,Mouseevent,作为我上一个问题的继续(或者重新表述),我试图检测光标是否位于以前隐藏、现在已淡入元素的上方,而不实际移动光标 设置如下:当一个元素消失在鼠标下方时,让鼠标完全静止。淡入动画完成后,脚本应检测到新显示的元素实际上位于光标下方,然后通过jQuery.trigger()或类似方式触发鼠标事件 在下面提供的提琴中,红色框仅指示光标的放置位置;这是不可利用的。也许最重要的是,我想知道是否有可能在不跟踪鼠标坐标的情况下完成此任务。 小提琴: 代码: 像这样的怎么样 基本上,您可以在要检查鼠标悬停的元素上
jQuery.trigger()
或类似方式触发鼠标事件
在下面提供的提琴中,红色框仅指示光标的放置位置;这是不可利用的。也许最重要的是,我想知道是否有可能在不跟踪鼠标坐标的情况下完成此任务。
小提琴:
代码:
像这样的怎么样 基本上,您可以在要检查鼠标悬停的元素上设置一个数据参数,然后在检查该参数时查看该参数
这将是一个惊人的解决方案,但它不工作的Chrome36或InternetExplorer11+;只有Firefox31。
setTimeout(function() {
//Fades in the element
$('#kitty').fadeIn('slow', function() {
//This verifies that the element exists
if ($('#kitty').length != 0) {
//Do something to detect that #kitty is underneath the mouse cursor
}
});
}, 3000);
$('#kitty').mouseenter(function() {
$(this).css({
'transform': 'scale(1.5)',
'transition': 'transform 500ms'
});
}).mouseleave(function() {
$(this).css({
'transform': 'scale(1)',
'transition': 'transform 500ms'
});
});
setTimeout(function() {
$('#kitty').fadeIn('slow', function() {
if ($('#kitty').length != 0) {
if($('#kitty').data("hovering") == "yes")
{
//Take whatever your intended action is
alert("hovering");
}
}
});
}, 3000);
$('#kitty').mouseenter(function() {
$(this).css({
'transform': 'scale(1.5)',
'transition': 'transform 500ms'
});
//Set the data parameter
$(this).data("hovering","yes");
}).mouseleave(function() {
$(this).css({
'transform': 'scale(1)',
'transition': 'transform 500ms'
});
//Unset the parameter when the mouse leaves
$(this).data("hovering","");
});