jQuery'mmenu'打开时的回调事件

问题描述 投票:5回答:3

使用jQuery mmenu plugin我需要在菜单打开后调用JavaScript函数。我无法从API documentation看到如何使用插件API来做到这一点,所以我想也许唯一的选择是观察<html>元素上的类名,当菜单打开时它会获得一类mm-opened 。这感觉有点'hacky',所以我想知道是否有人能够在本机API的范围内看到一种方法来完成所需的函数调用?

编辑:与预期相反,当打开菜单时,openPanel事件不会触发 - 它只在子菜单打开时触发,因此虽然这表明它可以完成工作但事实并非如此。

非常感谢。

jquery jquery-plugins mmenu
3个回答
15
投票

得到它(没有记录!):

var api = $('#menu').data('mmenu');
api.bind('opened', function () {
    console.log('opened');
});

5
投票

您可以在源代码中搜索.trigger(https://raw.githubusercontent.com/FrDH/jQuery.mmenu/master/dist/js/jquery.mmenu.min.js

您将找到以下事件:

  • 在里面
  • 更新
  • 的setSelected
  • setPage
  • 打开
  • 开盘
  • 打开
  • 关闭
  • 关闭
  • openPanel
  • openingPanel
  • openedPanel
  • closePanel
  • closingPanel
  • closedPanel

我相信是这样的。在其中,您可以看到对您的案例有用的“已打开”和“已关闭”事件。


1
投票
var api = self.$el.data("mmenu");

api.bind('close:finish', function() {
   console.log('close');
});

api.bind('open:finish', function () {
   console.log('open');
});

感谢ChezFre

© www.soinside.com 2019 - 2024. All rights reserved.