请原谅标题的措辞,但总结起来很难。将鼠标悬停在元素更改元素上,然后将鼠标悬停在
这就是我想要做的
<div id="test">Test</div>
<div id="example1" style="display:none;">Test</div>
<div id="example2" style="display:none;">Test</div>
当#test
悬停,它会导致#example1
和#exmaple2
徘徊中止,#example1
和#exmaple2
再次返回到无形之中时变得可见,然后。
明显的简单代码。
$('#test').hover(
function() {
$('#example1,#example2').show();
},
function() {
$('#example1,#example2').hide();
}
);
现在,这里的困境。我需要#example1
和#exmaple2
在鼠标悬停时保持可见状态,这是不可能的,因为当鼠标离开#test
时,鼠标悬停在#example1
或#example2
上,它们会回到隐形状态,正如上面的代码所指示的那样。我怎样才能使这成为可能?
我明白包装的元素这样在一起
<div id="wrapper">
<div id="test">Test</div>
<div id="example1" style="display:none;">Test</div>
<div id="example2" style="display:none;">Test</div>
</div>
和更改代码
$('#wrapper').hover(
function() {
$('#example1,#example2').show();
},
function() {
$('#example1,#example2').hide();
}
);
可以解决这个问题,但我不能这样做,因为在我的实际代码, #test
已经在包装下了,这是一个包装,它具有与之相关的非常具体的设计,如果我在其中包含#example1
和#example2
,它将被销毁。
综上所述上面,我的问题是:当#test
悬停和#example1
和#example2
变得可见,我怎能#example1
和#example2
可见离开#test
即使悬停在#example1
和#example2
?
正如我上文所述,我已经有'在我的代码不同的包装#test',它是高度专用的,所以'#example1'和'#example2'会毁了它。我想知道在重做我的整个代码之前是否有办法在jQuery或JavaScript中做到这一点。 – Odyssey 2011-12-19 02:19:25
@Odyssey我已经添加了解决方案的另一半。 – shinkou 2011-12-19 02:31:35
这给了我'位置:绝对'和'边缘顶部'的想法,它的工作方式就像我需要的一样! – Odyssey 2011-12-22 01:17:05