鼠标悬停时显示 div
我有一堆嵌套的 div、ul 等。结构如下所示。
<script>
$(document).ready(function() {
$('#top-level').mouseover( function() {
$( this ).find('.action').show();
$( this ).find('.drop').show('slide');
});
$('#top-level').mouseout( function(){
$( this ).find('.drop').hide('blind', function(){
$('.action').hide();
});
});
</script>
<div id="top-level">
<div>
<div class="action" style="display:none;">
<ul class="drop" style="display:none;">
<li>Text Here</li>
<li>Text Here</li>
<li>Text Here</li>
</ul>
</div>
</div>
</div>
此处显示的 ul 是在翻转时显示的。 .drop css 设置为position:absolute,以便它出现在顶级div 上方。
因此,ul 水滴看起来不错,但一旦它接触到鼠标光标,它就会变得疯狂(不停地上下百叶窗等)!现在,这与鼠标在某种程度上失去焦点有关。
为了让这种效果正常发挥,我应该怎样做呢?我希望能够滚动 div 并在出现后从 drop ul 中选择选项。
提前致谢。
I've got a bunch of nested divs, ul's etc. Structure is shown here.
<script>
$(document).ready(function() {
$('#top-level').mouseover( function() {
$( this ).find('.action').show();
$( this ).find('.drop').show('slide');
});
$('#top-level').mouseout( function(){
$( this ).find('.drop').hide('blind', function(){
$('.action').hide();
});
});
</script>
<div id="top-level">
<div>
<div class="action" style="display:none;">
<ul class="drop" style="display:none;">
<li>Text Here</li>
<li>Text Here</li>
<li>Text Here</li>
</ul>
</div>
</div>
</div>
The ul shown here is being shown on a rollover. The .drop css is set as position:absolute so that it appears over the top-level div.
So, the ul drop appears nicely but as soon as it come in contact with the mouse cursor it goes mad (blinds up and down non stop etc)! Now this will have something to do with the mouse over losing focus in some way.
For this sort of effect to work properly how should I go about it? I want to be able to scroll over the div and chose options from the drop ul after it appears.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://jsfiddle.net/PDdKL/
使用悬停:
http://jsfiddle.net/PDdKL/
Use hover instead:
使用鼠标进入和鼠标离开。
Use mouseenter and mouseleave.
您可以在每个事件处理程序的开头使用
$(element).stop();
来停止该元素上的动画。you can use
$(element).stop();
in the beginning of every event handler to stop animations on that element.我做了这样的东西供人查看;
http://jsfiddle.net/RyanAdriano/AWm66/8/
I made something like this for someone check it out here;
http://jsfiddle.net/RyanAdriano/AWm66/8/