抱歉我的英文... 我有一个基于Wordpress的单页网站。 我在我的页面上添加了一些锚点,但是在桌面版本中,菜单在我点击相对于其中一个锚点(或普通链接)的链接后关闭。 当我在一个小屏幕上时,菜单在点击一个锚点后没有关闭(正常的链接ID),页面只会转到锚点,但由于菜单而保持不可见。 我查看了这个主题:How to Close toggle menu when clicking navigation item anchor link但我不知道如何修改文件来修复它。 这是我的菜单代码:
/**
* navigation.js
*
* Handles toggling the navigation menu for small screens.
*/
( function() {
var container, button, menu;
container = document.getElementById( 'site-navigation' );
if ( ! container ) {
return;
}
button = container.getElementsByTagName( 'button' )[0];
if ( 'undefined' === typeof button ) {
return;
}
menu = container.getElementsByTagName( 'ul' )[0];
// Hide menu toggle button if menu is empty and return early.
if ( 'undefined' === typeof menu ) {
button.style.display = 'none';
return;
}
menu.setAttribute( 'aria-expanded', 'false' );
if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
menu.className += ' nav-menu';
}
button.onclick = function() {
if ( -1 !== container.className.indexOf( 'toggled' ) ) {
container.className = container.className.replace( ' toggled', '' );
button.setAttribute( 'aria-expanded', 'false' );
menu.setAttribute( 'aria-expanded', 'false' );
} else {
container.className += ' toggled';
button.setAttribute( 'aria-expanded', 'true' );
menu.setAttribute( 'aria-expanded', 'true' );
}
};
} )();
您能否告诉我如何修改此代码以在单击锚点后自动关闭它?我认为"区域扩展"的价值定义菜单的状态?
感谢您的帮助