当用户在弹出菜单外部单击时,我是否应该隐藏弹出菜单
我有一个包含“按钮”的水平菜单。单击该按钮将打开一个子菜单(不需要在悬停时打开菜单)。单击同一个按钮时,子菜单将被隐藏,如下所示:
标记
<div class="toolbar">
<div class="popout-wrap">
<div class="button">
</div>
<div class="popout">
blah blah blah
</div>
</div>
<div class="popout-wrap">
<div class="button">
</div>
<div class="popout">
blah blah blah
</div>
</div>
...
jQuery 代码
$(".popout-wrap .button").click(function () {
var menu = $(this).siblings(".popout");
if (menu.is(":hidden")) {
$(".popout").not(":hidden").fadeOut("fast");
menu.css("top", -1 * (menu.outerHeight() + 8) + "px");
menu.fadeIn("fast");
} else {
menu.fadeOut("fast");
}
return false;
});
要求用户单击同一个按钮来隐藏其相应的子菜单不是很直观。使它更加直观/本能/易于使用的最佳方法是什么?我认为单击文档中的任何位置都会关闭弹出菜单,但不确定是否(i)这是一个好主意(ii)如果是那么如何实现它。
I have a horizontal menu that contains "buttons". Clicking on the button opens a sub-menu (opening menu on hover is NOT required). When the same button is clicked, the sub-menus are hidden, like this:
Markup
<div class="toolbar">
<div class="popout-wrap">
<div class="button">
</div>
<div class="popout">
blah blah blah
</div>
</div>
<div class="popout-wrap">
<div class="button">
</div>
<div class="popout">
blah blah blah
</div>
</div>
...
jQuery code
$(".popout-wrap .button").click(function () {
var menu = $(this).siblings(".popout");
if (menu.is(":hidden")) {
$(".popout").not(":hidden").fadeOut("fast");
menu.css("top", -1 * (menu.outerHeight() + 8) + "px");
menu.fadeIn("fast");
} else {
menu.fadeOut("fast");
}
return false;
});
Asking the user to click on the same button to hide its corresponding sub-menu is not very intuitive. What's the best way to make it more intuitive/instinctive/easy to use? I thought clicking anywhere in the document would dismiss the popup menu but not sure if (i) it is a good idea (ii) if it is then how to implement it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我保证
mouseout
方法带有超时功能。基本上,用户必须在元素之外花费至少一定的时间(按下的按钮和弹出的菜单)。I vouch for the
mouseout
method spiced with a timeout. Basically the user has to spend at least acertain amount of time outside your elements (the button which was pressed and the menu which popped out).鼠标移出是可以的,但我也会将其与文档中任意位置的单击连接起来,因为这就是弹出窗口在大多数操作系统上的工作方式:
mouse out is ok but i would also connect it with the click anywhere in the document as thats how popups works on most OS:
也许向button()添加一个模糊处理程序并关闭该处理程序中的弹出窗口。
除了它不是一个真正的按钮之外,它是一个 div,因此不会接收焦点,因此不会发生模糊事件。为什么不把它们做成真正的按钮呢?
perhaps add a blur handler to the button() and dismiss the popup in that handler.
Except its not a real button, its a div so wont recieve focus, so hence no blur event. Why not make them real buttons?