这是我为一个简单的导航栏准备的一些 JavaScript,但是我遇到了下拉菜单在您单击它们之前消失的问题,所以我想在鼠标离开导航栏后添加延迟,然后再隐藏。
我该怎么做?
<script type="text/javascript">
$(document).ready(function () {
// Navigation bar drop-down
$("nav ul li").hover(function () {
$(this).addClass("active");
$(this).find("ul").show().animate({ opacity: 1 }, 400);
}, function () {
// Delay on hiding should go here
$(this).find("ul").hide().animate({ opacity: 0 }, 200);
$(this).removeClass("active");
});
$('nav ul li ul li:first-child').prepend('<li class="arrow"></li>');
$('nav ul li:first-child').addClass('first');
$('nav ul li:last-child').addClass('last');
$('nav ul li ul').parent().append('<span class="dropdown"></span>').addClass('drop');
});
</script>
提前感谢任何可以提供帮助的人
PS 这可能很明显,但我对 JavaScript 知之甚少。:L