悬停或单击时激活 JQuery 菜单
我的目标是动画 JQuery 菜单以在悬停或单击时做出响应。使用 HoverIntent 插件,以下代码可以按预期悬停。但是如何在保持用户友好的菜单的同时添加点击事件呢?在计划如何编写此内容时,我考虑过在单击菜单项时向悬停事件添加延迟,但我不确定该实现的实用性。如何将点击事件添加到以下代码中?
<script type="text/javascript">
$(document).ready(function() {
function show() {
var menu = $(this);
menu.children(".options").slideDown();
}
function hide() {
var menu = $(this);
menu.children(".options").slideUp();
}
$(".menuHeader").hoverIntent({
sensitivity: 3,
interval: 50,
over: show,
timeout: 300,
out: hide
});
});
<div id="SideMenu">
<div id="aMenu" class="menuHeader">
<h2>Menu A</h2>
<ul class="options" >
<li><a href="">Option a1</a></li>
<li><a href="">Option a2</a></li>
<li><a href="">Option a3</a></li>
</ul>
</div>
<div id="bMenu" class="menuHeader">
<h2>Menu B</h2>
<ul class="options" >
<li><a href="">Option b1</a></li>
<li><a href="">Option b2</a></li>
<li><a href="">Option b3</a></li>
</ul>
</div>
<div id="cMenu" class="menuHeader">
<h2>Menu C</h2>
<ul class="options" >
<li><a href="">Option c1</a></li>
<li><a href="">Option c2</a></li>
<li><a href="">Option c3</a></li>
</ul>
</div>
</div>
对于代码的格式感到抱歉,感谢您的帮助。
My goal is to animate a JQuery menu to respond when hovered or clicked. Using the HoverIntent plugin the following code is working as intended to hover. But how do I add a click event while maintaining a user friendly menu? While planning how to write this I have considered adding a delay to the hover event when a menu item is clicked, however I am unsure how practical that implementation would be. How would I add the click event to the following code?
<script type="text/javascript">
$(document).ready(function() {
function show() {
var menu = $(this);
menu.children(".options").slideDown();
}
function hide() {
var menu = $(this);
menu.children(".options").slideUp();
}
$(".menuHeader").hoverIntent({
sensitivity: 3,
interval: 50,
over: show,
timeout: 300,
out: hide
});
});
<div id="SideMenu">
<div id="aMenu" class="menuHeader">
<h2>Menu A</h2>
<ul class="options" >
<li><a href="">Option a1</a></li>
<li><a href="">Option a2</a></li>
<li><a href="">Option a3</a></li>
</ul>
</div>
<div id="bMenu" class="menuHeader">
<h2>Menu B</h2>
<ul class="options" >
<li><a href="">Option b1</a></li>
<li><a href="">Option b2</a></li>
<li><a href="">Option b3</a></li>
</ul>
</div>
<div id="cMenu" class="menuHeader">
<h2>Menu C</h2>
<ul class="options" >
<li><a href="">Option c1</a></li>
<li><a href="">Option c2</a></li>
<li><a href="">Option c3</a></li>
</ul>
</div>
</div>
Sorry about the formatting of the code, and thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有使用过hoverIntent,有什么办法可以解除绑定吗?
如果有的话,你可以这样做:
所以你点击了一个链接,它会堆叠起来,直到你鼠标移开,然后当你再次悬停它或点击它时,它会再次堆叠。
编辑:
您还需要从hoverIntent中取消绑定click on函数,否则当您单击链接时会产生奇怪的效果。
I never used hoverIntent, there's anyway to unbind it?
If there's you can do something like this:
So you clicked a link, it will stack until you mouseout, and then when you hover it again or click on it it will stack again.
Edit:
You also need to unbind click on over function from the hoverIntent or it will cause a weird effect when you click the link.