使用 MouseOver 事件控制 dijit.MenuBar

发布于 2024-12-11 11:42:09 字数 384 浏览 0 评论 0原文

在Dojo中,是否可以配置dijit.MenuBar以便由MouseOver和MouseOut事件触发菜单?实际上,这种行为已经可用,但它是通过初始或连续的鼠标单击事件来打开或关闭的 - 因此最初,MouseOver 不会导致菜单弹出,但如果用户单击菜单项,菜单栏就会响应 MouseOver 事件。连续单击鼠标将再次关闭此行为。

我想要的是基于 MouseOver 事件弹出的菜单和子菜单,而不受单击事件的干扰。请查看 http://dojotoolkit.org/reference-guide/dijit/MenuBar 中的示例。 html 看看我的意思。

In Dojo, is it possible to configure dijit.MenuBar so that the menus are triggered by MouseOver and MouseOut events? Actually this behavior is available already, but it is switched on or off by initial or successive mouse click events - so initially, MouseOver would not cause menu popup, but if the user clicks on a menu item, the menubar then becomes responsive to MouseOver events. A successive mouse click would again switch off this behavior.

What I would like to have is menus and sub-menus popping up based on MouseOver events without interference from click events. Please check the examples at http://dojotoolkit.org/reference-guide/dijit/MenuBar.html to see what I mean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还给你自由 2024-12-18 11:42:10

下面是一个示例,将“Hugomg”的解决方案扩展到取消悬停菜单和子菜单的情况:
[在此输入链接描述][1]

[1]: http://jsfiddle.net/vg10c9md/2/

Here is an example that extends the solution of 'Hugomg' to case of unhovering the menu and the sub-menu:
[enter link description here][1]

[1]: http://jsfiddle.net/vg10c9md/2/
耳根太软 2024-12-18 11:42:09

你的问题引起了我的兴趣,足以制定一个工作解决方案

我在 dijit/Menu.js 检查了 dijit._MenuBase 源代码,显然在继续之前检查了一个 this.isActive 标志。所以我创建了一个子类,只是预先将此标志设置为 true:

_ActivateOnMouseoverMixin = dojo.declare(null, {
    onItemHover: function(item){
        if(!this.isActive){
            this._markActive();
        }
        this.inherited(arguments);
    }
});

ActiveMenuBar = dojo.declare([dijit.MenuBar, _ActivateOnMouseoverMixin], {});

作为奖励,您还可以使用 popupDelay 变量修改延迟(我在示例中将其更改为更快)


我不知道是否还有另一个更理智的,做同样的事情的方法。

Your question piqued my interest enough to make a working solution.

I checked the dijit._MenuBase source code at dijit/Menu.js and apparently there is a this.isActive flag that is checked before proceeding. So I created a subclass that just sets this flag as true beforehand:

_ActivateOnMouseoverMixin = dojo.declare(null, {
    onItemHover: function(item){
        if(!this.isActive){
            this._markActive();
        }
        this.inherited(arguments);
    }
});

ActiveMenuBar = dojo.declare([dijit.MenuBar, _ActivateOnMouseoverMixin], {});

As a bonus, you can also modify the delay with the popupDelay variable (I changed it to be faster in the example)


I have no idea if there is another, more sane, way to do the same thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文