我有一个简单的水平菜单,当我将每个项目悬停时,子菜单向下滑动.所以基本上它是我们经常看到的典型导航菜单.当鼠标移出时,当我将鼠标悬停在子菜单上时向下滑动.我的问题是,如果我在项目中快速移动鼠标,则会发生多个子菜单保持可见状态.我想这是因为当我触发滑动时滑动没有完成.有什么想法可以防止这个?继承我的代码:
$('#menu > li').hover(
function () {
$('ul',$(this)).slideDown();
},
function () {
$('ul',$(this)).slideUp();
}
);
Run Code Online (Sandbox Code Playgroud)
谢谢!
You should call stop before sliding up and down, and from your description, you should also pass true for both optional parameters like this:
$('ul',$(this)).stop(true, true).slideDown();
Run Code Online (Sandbox Code Playgroud)
The first parameter (clearQueue) tells jQuery to clear the animation queue, stopping any queued animations.
The second parameter (gotoEnd) tells jQuery to complete the current animation. (This parameter might not be necessary in your case, depending on the effect you want.)
| 归档时间: |
|
| 查看次数: |
803 次 |
| 最近记录: |