jQuery show/hide - Question about the delay variable

帅比萌擦擦* 提交于 2019-12-05 04:56:14

There's a very nice plugin written in jQuery specifically for this type of mouse enter / leave functionality.

It's called hoverIntent.js

It creates a configurable delay before performing the next slide action etc, great for menu interactions. You can also call your own functions on each of the expiry events.

An example of the default usage is:

$("#menu li").hover( showMenu, fadeMenu)

Whereby fadeMenu and showMenu would be your jQuery functions to change the appearance of the menu.

To create your own configuration of the delay you simply use:

var config = {    
     over: showMenu,  
     timeout: 500, // number = milliseconds delay before fadeMenu is called
     out: fadeMenu 
};

$("#menu li").hoverIntent( config )

Edit:

For you example, so long as the is the trigger to show the hidden div then you should be able to use the following:

var config = {    
     over: showMenu,  
     timeout: 500, // number = milliseconds delay before fadeMenu is called
     out: fadeMenu 
};

$("#cart-box a").hoverIntent( config );

function showMenu() {
    jQuery("#cart-container").fadeIn('fast');
}

function fadeMenu() {
    jQuery("#cart-container").fadeOut('fast');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!