简体   繁体   English

jQuery菜单的幻灯片悬停功能加载太快

[英]jquery menu slideshow hover function loading too fast

I am currently making a website that includes a menu navigation almost identical to the one found at fotopunch.com only instead of pointing down it points up. 我目前正在制作一个包含菜单导航的网站,该菜单导航与fotopunch.com上的菜单导航几乎完全相同,而不是指向上方。 Anyways, I wrote the code using jquery/javascript for the menu and it works but I am wondering if there is a way to make it so that the hover function doesn't take effect for a specified amount of time. 无论如何,我使用菜单的jquery / javascript编写了代码,它可以工作,但是我想知道是否有一种方法可以使悬停功能在指定的时间内不起作用。 That way when you hover quickly over an item it doesn't cause the page to load unnecessarily. 这样,当您将鼠标悬停在某个项目上时,不会导致页面不必要地加载。 If anyone has any suggestions I would greatly appreciate it. 如果有人有任何建议,我将不胜感激。

Below is a copy of part of my code to create the menu navigation. 以下是我创建菜单导航的部分代码的副本。 Another issue I am having is if you hover over too many navigation items in a row the arrow lags behind. 我遇到的另一个问题是,如果您将鼠标悬停在太多的导航项目上,则箭头会滞后。 I am hoping that by creating a wait time before the hover function takes effect that it would mostly correct this issue. 我希望通过在悬停功能生效之前创建一个等待时间来大部分解决此问题。

$("div#menu .reps").hover(function() {

if(current_slide != "reps"){
    $(".arrow").animate({"left":"135px"});//move the arrow
    if(current_slide == "clients"){
        $(".clients_display").stop(true, true).fadeOut().hide();
        $(".reps_display").fadeIn().show();
        current_slide = "reps";
    }
    else if(current_slide == "services"){
        $(".services_display").stop(true, true).fadeOut().hide();
        $(".reps_display").fadeIn().show();
        current_slide = "reps";
    }
    else{
        $(".training_display").stop(true, true).fadeOut().hide();
        $(".reps_display").fadeIn().show();
        current_slide = "reps";
    }
}
});

You an use the delay on some of your calls such as: 您在某些通话中使用delay ,例如:

$(".reps_display").delay(100).fadeIn().show();

Or you can make some of the show and hide have a longer duration: show(2000) for instance. 或者,您可以使某些showhide的持续时间更长:例如show(2000)

I think that something that you can do, although there is probably a better way is: 我认为您可以执行一些操作,尽管可能有更好的方法是:

declare a function where you place all the code with a condition: 声明一个函数,在其中将所有代码置于条件下:

function hoverFunc(option)
{
    if($(option).is(':hover'))
    {
      all the code to show the menu
    }
}

And on the over function you do: 然后在over函数上执行以下操作:

$("div#menu .reps").hover(function() {
   setTimeout("hoverFunc('"+getOptionName+"')",milliseconds);
});

The idea is: when over, set a timeout and when the timeout is reached, check if the mouse is over and then do whatever you want, the hardest point is to pass the reference to the function, but you can pass the name of the item just getting it from html or a rel attribute. 这个想法是:结束时,设置一个超时,当超时时,检查鼠标是否结束,然后做任何您想做的事情,最困难的一点是将引用传递给该函数,但是您可以传递该函数的名称。只是从html或rel属性获取的项目。

But if you dont need the reference it is really ease, just call the function and check the element. 但是,如果您不需要引用,那确实很容易,只需调用函数并检查元素即可。


There is another option that maybe is more interesting for you. 还有另一个选项可能对您来说更有趣。 You can add a delay to the all the effects and add a stop(true) before, this way, if the user change the tag fast, the events will be cancelled, but it will change if the user goes through an option fast and goes out of the menu. 您可以在所有效果上添加延迟,然后在之前添加stop(true),这样,如果用户快速更改标签,事件将被取消,但是如果用户快速通过一个选项并转到在菜单之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM