Javascript Jquery鼠标事件替代方案

Javascript Jquery鼠标事件替代方案,javascript,jquery,Javascript,Jquery,好的,如果我在导航分区外单击,下面的代码可以正常工作。我在问是否可以将鼠标移离导航分区使其消失。我不想“单击”隐藏div 我试过mouseenter和mouseleav,但都不行。 如有任何帮助,我们将不胜感激:请尝试以下方法: $(document).ready(function(){ $("#logo").mouseover(function() { $("#nav").fadeIn("slow"); }); $("#nav").mouseleave(function (e){

好的,如果我在导航分区外单击,下面的代码可以正常工作。我在问是否可以将鼠标移离导航分区使其消失。我不想“单击”隐藏div

我试过mouseenter和mouseleav,但都不行。 如有任何帮助,我们将不胜感激:

请尝试以下方法:

$(document).ready(function(){
   $("#logo").mouseover(function() { $("#nav").fadeIn("slow"); });

   $("#nav").mouseleave(function (e){
       $(this).fadeOut("slow");
   });
});
试试这个:

$(document).ready(function(){
   $("#logo").mouseover(function() { $("#nav").fadeIn("slow"); });

   $("#nav").mouseleave(function (e){
       $(this).fadeOut("slow");
   });
});

你需要一个鼠标在导航我已经为你添加了检查下面的链接

$(document).ready(function(){
$("#logo").mouseenter(function() { $("#nav").fadeIn("slow"); });
});

$("#nav").mouseleave(function (e)
{
       $("#nav").fadeOut('fast');
});

如果你想制作一个下拉菜单,我建议你看看这里的链接:它使用纯CSS进行下拉,因此当用户没有启用Javascript时,它也可以工作

您需要导航上的鼠标,我已经为您添加了鼠标,请查看下面的链接

$(document).ready(function(){
$("#logo").mouseenter(function() { $("#nav").fadeIn("slow"); });
});

$("#nav").mouseleave(function (e)
{
       $("#nav").fadeOut('fast');
});
如果你想制作一个下拉菜单,我建议你看看这里的链接:它使用纯CSS进行下拉,因此当用户没有启用Javascript时,它也可以工作

导航div和徽标div之间的边距导致出现问题。当用户在这些区域之间引导鼠标时,并且您严格地在nav div上设置了mouseout事件,它会导致窗口关闭。解决方案是添加一个小的超时,让用户有时间在关闭菜单之前浏览菜单。这将避免用户意外地将鼠标移动到导航的边缘,并且可能在div之外一到两个像素的情况

下面是我用来解决这个问题的jQuery:

$('#nav').mouseover(function () {
    clearTimeout($.data(this, 'mouseOutTimer'));
});
$('#nav').mouseout(function () {
    clearTimeout($.data(this, 'mouseOutTimer'));
    $.data(this, 'mouseOutTimer', setTimeout(function () {
        $("#nav").hide();
    }, 700));
});
导航div和徽标div之间的边距导致出现问题。当用户在这些区域之间引导鼠标时,并且您严格地在nav div上设置了mouseout事件,它会导致窗口关闭。解决方案是添加一个小的超时,让用户有时间在关闭菜单之前浏览菜单。这将避免用户意外地将鼠标移动到导航的边缘,并且可能在div之外一到两个像素的情况

下面是我用来解决这个问题的jQuery:

$('#nav').mouseover(function () {
    clearTimeout($.data(this, 'mouseOutTimer'));
});
$('#nav').mouseout(function () {
    clearTimeout($.data(this, 'mouseOutTimer'));
    $.data(this, 'mouseOutTimer', setTimeout(function () {
        $("#nav").hide();
    }, 700));
});

您需要将事件处理程序绑定到所涉及的元素,而不是$document。还可以尝试mouseover和mouseoutmouseinter,mouseleave看起来对我很有效。有什么问题吗?mouseleave为我工作了,怎么了?请不要重新发布你的问题。如果您以前得到的答案对您不起作用,请与发布答案的人员联系,他们可能会帮助您找出代码的其他错误。您需要将事件处理程序绑定到相关元素,不是$document。也可以尝试mouseover和mouseoutmouseinter,mouseleave看起来对我很有效。有什么问题吗?mouseleave为我工作了,怎么了?请不要重新发布你的问题。如果你以前得到的答案对你不起作用,那么把它告诉发布它们的人,他们可能会帮助你找出你的代码还有什么问题。