0

我为下拉菜单做了自己的延迟功能。由于我对 JavaScript 有点陌生,我想知道这是否可以以更好的方式完成?

var $hasSubpages = $("#divContainer .classForPagesWithSubpages");

function theFunction(){$('#theID').find('.classForChild').slideDown(400);}

var timer;
$hasSubpages.hover(
    function (){
        timer = setTimeout(theFunction, 500);
        $(this).attr('id','theID');
    },
    function(){
        clearTimeout(timer);
        $(this).attr('id','').find('.classForChild').slideUp(400);
    }
);
4

2 回答 2

1

已经为此开发了一个名为 hoverIntent 的漂亮插件。

http://plugins.jquery.com/project/hoverIntent

如果您需要任何帮助来了解它的工作原理,我可以告诉您。否则它很容易使用。

于 2011-04-04T05:17:18.097 回答
0

使用延迟()函数

$('#test').slideDown(500).delay(3000).slideUp(500);

这将导致元素向下滑动等待 3 秒,然后再向上滑动

在http://jsfiddle.net/wanJf/检查工作示例

于 2011-04-04T08:06:21.510 回答