使用鼠标悬停和jQuery显示/隐藏(Show / Hide using mouseover and jQuery)

我有这段代码。 我的想法是,当我将mouseover li#anchor ,之前隐藏的ul#seeMore应该显示出来。

jQuery(document).ready(function(){ jQuery("li#anchor").mouseenter(function() { jQuery('ul#seeMore').css("display","block"); }); jQuery("li#anchor").mouseleave(function() { setTimeout( function(){ jQuery('ul#seeMore').css("display","none"); },1000); }); })

问题是我还想要第二个mouseleave函数不应该发生如果我还在盘旋ul#seeMore

或者,问题应该是:我怎样才能确定我是否不会徘徊在ul#seeMore ?

我试图改变jQuery("li#anchor").mouseleave(function() { to jQuery("ul#seeMore").mouseleave(function() {但似乎这不是很稳定。

I have this block of code. The idea is, that when I mouseover li#anchor, previously hidden ul#seeMore should show up.

jQuery(document).ready(function(){ jQuery("li#anchor").mouseenter(function() { jQuery('ul#seeMore').css("display","block"); }); jQuery("li#anchor").mouseleave(function() { setTimeout( function(){ jQuery('ul#seeMore').css("display","none"); },1000); }); })

The problem is that I also want that the second mouseleave function should not happen if I am still hovering the ul#seeMore

Or, probably the question should be: How can I ascertain if I'm not hovering the ul#seeMore?

I tried to change jQuery("li#anchor").mouseleave(function() { to jQuery("ul#seeMore").mouseleave(function() { but it seems this is not very stable.

最满意答案

你可以把ul#seemore放在li#anchor元素里面。 这样,当鼠标上升时, ul#seemore ,它将成为li#anchor元素

You can put ul#seemore inside li#anchor element. This way, when the mouse is up ul#seemore, it will be up the li#anchor element

使用鼠标悬停和jQuery显示/隐藏(Show / Hide using mouseover and jQuery)

我有这段代码。 我的想法是,当我将mouseover li#anchor ,之前隐藏的ul#seeMore应该显示出来。

jQuery(document).ready(function(){ jQuery("li#anchor").mouseenter(function() { jQuery('ul#seeMore').css("display","block"); }); jQuery("li#anchor").mouseleave(function() { setTimeout( function(){ jQuery('ul#seeMore').css("display","none"); },1000); }); })

问题是我还想要第二个mouseleave函数不应该发生如果我还在盘旋ul#seeMore

或者,问题应该是:我怎样才能确定我是否不会徘徊在ul#seeMore ?

我试图改变jQuery("li#anchor").mouseleave(function() { to jQuery("ul#seeMore").mouseleave(function() {但似乎这不是很稳定。

I have this block of code. The idea is, that when I mouseover li#anchor, previously hidden ul#seeMore should show up.

jQuery(document).ready(function(){ jQuery("li#anchor").mouseenter(function() { jQuery('ul#seeMore').css("display","block"); }); jQuery("li#anchor").mouseleave(function() { setTimeout( function(){ jQuery('ul#seeMore').css("display","none"); },1000); }); })

The problem is that I also want that the second mouseleave function should not happen if I am still hovering the ul#seeMore

Or, probably the question should be: How can I ascertain if I'm not hovering the ul#seeMore?

I tried to change jQuery("li#anchor").mouseleave(function() { to jQuery("ul#seeMore").mouseleave(function() { but it seems this is not very stable.

最满意答案

你可以把ul#seemore放在li#anchor元素里面。 这样,当鼠标上升时, ul#seemore ,它将成为li#anchor元素

You can put ul#seemore inside li#anchor element. This way, when the mouse is up ul#seemore, it will be up the li#anchor element