【发布时间】:2015-11-23 20:34:32
【问题描述】:
我正在使用mmenu 来创建一个不错的响应式菜单。它工作得很好,但我希望它打开与当前 url 匹配的列表项。这样,如果您进入网站并打开菜单,您可以立即看到您所在的位置。我一直在尝试使用 api 来实现此功能。
有关 mmenu 的 api 文档,请参见上面的链接。
我的代码:
var url = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
var api = $("nav#menu").data("mmenu");
api.bind("openPanel", function($panel) {
console.log("This panel is now opened:" + $panel.attr("id")); //Works
var href = $panel.find("li a").attr("href");
if (href == url) {
api.openPanel($panel); //Open the panel where the matching link is - doesn't work
console.log("Success!" + href);
}
});
我就是无法让它工作。有什么想法吗?
【问题讨论】: