简体   繁体   English

如何将侧边菜单内容包含在自定义汉堡包图标中?

[英]How to include side menu content into a custom hamburger icon?

I managed to get a animated hamburger icon from Codepen on my page (www.elevendozen.com), while the icon does animates, I could not figure out how to include the side nav menu content with it. 我设法在我的页面(www.elevendozen.com)上从Codepen获得一个动画汉堡包图标,而图标确实动画,我无法弄清楚如何包含侧面导航菜单内容。 For example, when the icon is clicked, the menu does not slide out, vice versa. 例如,单击图标时,菜单不会滑出,反之亦然。

I'm currently using WP Mobile Menu pluggin but their icon does not animate. 我目前正在使用WP Mobile Menu插件,但他们的图标没有动画。 Could you help me ? 你可以帮帮我吗 ? Thanks ! 谢谢 !

<div id="mob-menu-left-panel mobmenu" class="mobmenu_content" onclick="closeNav()"

</div>

It's a bit confusing, you should be more specific. 这有点令人困惑,你应该更具体。 If I understand correctly your problem is that your menu doesn't show up when you click the icon ? 如果我理解正确您的问题是您单击图标时菜单没有显示?

In your div you have an onclick attribute that should be paired with javascript functions called closeNav() and openNav(). 在你的div中你有一个onclick属性,应该与名为closeNav()和openNav()的javascript函数配对。 Those functions are here to manage the slide in/out of the menu. 这些功能用于管理菜单中的滑入/滑出。 Without it, there's no chance to make the menu appear. 没有它,就没有机会出现菜单。

When we look at the developper javascript console, we get this error : 当我们查看developper javascript控制台时,我们收到此错误:

Uncaught TypeError: Cannot read property 'style' of null
at openNav ((index):81)
at HTMLButtonElement.<anonymous> ((index):92)

When we want to open the menu, and also : 当我们想要打开菜单时,还要:

Uncaught TypeError: Cannot read property 'style' of null
at closeNav ((index):86)
at HTMLButtonElement.<anonymous> ((index):92)

When we try to close the menu. 当我们尝试关闭菜单时。

If we look at the javascript file at index 92, it says : 如果我们查看索引为92的javascript文件,它会说:

hamburger.addEventListener('click', () => hamburger.classList.contains('is-active') ? closeNav() : openNav());

An addEventListener is here to watch if an event occurs. addEventListener用于监视事件是否发生。 In this case, a click. 在这种情况下,点击一下。 If a click occurs, depending if the hamburger got the 'is-active' class, it launches the close or open nav function. 如果发生咔嗒声,取决于汉堡包是否获得'is-active'类,它会启动关闭或打开导航功能。

In the closeNav and openNav function, the menu is identified via : 在closeNav和openNav函数中,菜单通过以下方式识别:

document.getElementById(".mob-menu-slideout-over.show-nav-left .mob-menu-left-panel").style.display = "none";

I think the problem is here. 我认为问题出在这里。 A getElementById function should target an element with an id. getElementById函数应该以具有id的元素为目标。 It seems that your menu got the navToShow id. 您的菜单似乎获得了navToShow ID。 You should do the link between this and the javascript function. 你应该在这个和javascript函数之间建立链接。

But it's just a suggestion not a definitive answer... 但这只是一个建议,而不是一个明确的答案......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM