$('.showmenu').bind("mouseenter", function (e) {
$('ul.secondul').show();
});
$('.showmenu').bind("mouseleave", function (e) {
$('ul.secondul').hide();
});
是否有办法让第二个函数不会立即启动,但在1秒的延迟之后?因此,当用户不小心将鼠标移出下拉菜单选项卡时,该选项卡将不会立即关闭,并让用户有机会将鼠标移回。因为它是一个类,你可以有更多的.showmenu
项目使用jquery设置延迟或超时
$('.showmenu')
.bind("mouseenter", function (e) {
if($(this).data("timer"))
clearTimeout($(this).data("timer"));
$('ul.secondul').show();
})
.bind("mouseleave", function (e) {
$(this).data("timer", setTimeout(function(){
$('ul.secondul').hide();
}, 1000));
});
使用$(this).data
:
使用悬停:http://api.jquery.com/hover/ – 2013-04-25 18:50:10
http://stackoverflow.com/questions/2939980/jquery-how-to-sleep-or-delay的重复和所以很多其他。 – Colleen 2013-04-25 18:51:21
@Colleen你错了。在这种情况下,Delay()不起作用。 – Jerry 2013-04-25 18:52:21