javascript - 我的子菜单项有时会卡在打开状态?
问题描述
我有一个菜单和移动设备,有时其中一个随机卡在打开并且不会关闭。
有人知道为什么吗?
这是我的Javascript:
/*** Sets or removes .focus class on an element.*/
function toggleFocus() {
if ( event.type === 'focus' || event.type === 'blur' ) {
let self = this;
// Move up through the ancestors of the current link until we hit .nav-menu.
while ( ! self.classList.contains( 'nav-menu' ) ) {
// On li elements toggle the class .focus.
if ( 'li' === self.tagName.toLowerCase() ) {
self.classList.toggle( 'focus' );
}
self = self.parentNode;
}
}
if ( event.type === 'touchstart' ) {
const menuItem = this.parentNode;
event.preventDefault();
for ( const link of menuItem.parentNode.children ) {
if ( menuItem !== link ) {
link.classList.remove( 'focus' );
}
}
menuItem.classList.toggle( 'focus' );
}
}
解决方案
推荐阅读
- python - 在 shell 或 Python 中使用 SFTP 递归获取文件列表,无需额外的库
- snakemake - snakemake 脚本访问标准输入/标准输出以进行流处理
- python - 屏蔽感兴趣区域后减小光栅大小
- javascript - 如何在嵌套对象中映射特定键值
- vue.js - 将渲染的 HTML 映射到 Vue.js 中的代码行
- laravel - 十月 CMS:在主题之间共享部分内容
- c# - xamarin 表单,自动完成位置地址
- php - url上的Laravel检查文件
- java - 在线程中运行消息循环
- c# - Microsoft.Extensions.Hosting EnvironmentName 覆盖默认生产值