JQuery 下拉菜单,将鼠标悬停在下拉菜单上时保持按下状态
我设置了一个完美的 jquery 下拉菜单。当用户将鼠标悬停在链接上时,它就会下降。问题在于,当用户将鼠标滑过下拉菜单的内容区域时,它会向上滑动。我需要设置代码,以便当用户的光标仍在其上方时,滑动框保持在向下位置。
这是我的 HTML:
<ul id="tabnav">
<li class="tab2"><a href="index2.html" class="btn-slide">My Leases</a></li>
</ul>
<div id="leases">
<!-- slide down content here -->
</div>
JS 触发器:
<script type="text/javascript">
$(document).ready(function(){
$(".btn-slide").hover(function(){
$("#leases").slideToggle("medium");
$(this).toggleClass("active");
return false;
});
});
</script>
有什么想法吗?
编辑:这是相关页面的链接: http://designvillain.com/testbed/600 /601.html
I setup a jquery dropdown menu that works perfect. It drops down when a user rolls over a link. The problem is that when the user rolls over the content area of the drop down menu, it slides back up. I need to set up the code so that the slidedown box remains in the down position while the user's cursor is still over it.
Here is my HTML:
<ul id="tabnav">
<li class="tab2"><a href="index2.html" class="btn-slide">My Leases</a></li>
</ul>
<div id="leases">
<!-- slide down content here -->
</div>
JS Trigger:
<script type="text/javascript">
$(document).ready(function(){
$(".btn-slide").hover(function(){
$("#leases").slideToggle("medium");
$(this).toggleClass("active");
return false;
});
});
</script>
Any ideas?
EDIT: Here is a link to page in question: http://designvillain.com/testbed/600/601.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否是你想要的,但我就把它放在这里。它会等待 500 毫秒,然后才会向上滑动
#leases
,并且仅在适当的情况下这是一个演示:http:// /jsfiddle.net/mMRZc/
I'm not sure if this is what you want, but I'll just drop it here. It waits 500ms before sliding up
#leases
, and only when appropriateHere's a demo: http://jsfiddle.net/mMRZc/
.hover() 绑定两个事件,mouseenter 和 mouseleave。
相反,我会更精细地使用 .btn-slide 上的 mouseenter() 和 .leases 上的 mouseleave()
编辑:注意,如果鼠标从未进入 #leases div,它将不会获得 mouseleave,并且您可能会需要考虑这一点。
EDIT2:修复我错误的功能手指输入功能
The .hover() binds two events, mouseenter and mouseleave.
I would instead go granular and use the mouseenter() on the .btn-slide and the mouseleave() on the .leases
EDIT: Note, if the mouse never enters the #leases div, it will not get the mouseleave, and you may need to consider that.
EDIT2: fix my bad finger typing of funciton to function
我假设 div 在页面加载时隐藏,并且您希望当您将鼠标悬停在链接上时显示它?将切换开关更改为向下...
是否需要有时向上滑动?
I assume the div is hidden on page load and you want it to show when you hover over the link? Change toggle to down...
Does it need to slide back up sometime?