首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Javascript导航菜单闪烁

Javascript导航菜单闪烁
EN

Stack Overflow用户
提问于 2021-06-27 20:48:50
回答 1查看 47关注 0票数 0

我有一个带有子链接的导航菜单。当我将鼠标放在有子链接的链接上时,当我将鼠标移到链接上时,它会闪烁。

对我的问题的说明:

https://i.ibb.co/g684pXt/illustr.gif

代码语言:javascript
运行
复制
function myFunction(i) {
  document.getElementById("myDropdown" + i).classList.toggle("show");
}

/* When the user clicks on the button, 
toggle between hiding and showing the dropdown content */
function yourFunction(i) {
  document.getElementById("myDropdown" + i).classList.toggle("show");

  document.getElementById("myDropdown" + i).children.classList.remove("show");
}
代码语言:javascript
运行
复制
<li class="active"><a href="{{ route('comparateur') }}">{{__('header.Comparer')}}</a></li>
<div class="d_1">
  <button href="{{ route('vpn.index') }}" onmouseover="myFunction(1)" class="d_btn">{{__('header.Meilleurs-VPN')}} <i class="fa fa-angle-down"></i></button>
  <div id="myDropdown1" onmouseout="yourFunction(1)" class="d_content d_mobile_1">

    <a href="{{ route('vpn.index') }}">Tous les VPN</a>

    <a href="{{ route('vpn.windows') }}">Windows</a>
    <a href="{{ route('vpn.ios') }}">{{__('header.Mac')}}</a>

    <a href="{{ route('vpn.linux') }}">{{__('header.Linux')}}</a>
    <a href="{{ route('vpn.android') }}">{{__('header.Android')}}</a>
    <a href="{{ route('vpn.netflix') }}">{{__('header.Netflix')}}</a>
  </div>
</div>

它可以工作,但导航不流畅,不好,因为当我在子菜单中移动鼠标时,子菜单在每个链接之间闪烁。

请帮帮忙!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-27 21:58:42

我会抛弃javascript,转而使用纯CSS。当你点击元素时,:focus会选择它,而x + y的意思是“如果它紧跟在x后面,就选择y”。

代码语言:javascript
运行
复制
button:focus + div {
  display: flex;
}

button + div {
  display: none;
  flex-direction: column;
}

/* ALL DECORATION BELOW AND NOT RELEVANT TO THE ISSUE */
button + div {
  padding: 0.5rem 0px;
  background: pink;
}

button + div > a {
  padding: 0.5rem;
}

button + div > a:hover {
  background: rgba(0, 0, 0, 0.13);
}
代码语言:javascript
运行
复制
<div class="d_1">
  <button href="{{ route('vpn.index') }}" class="d_btn">{{__('header.Meilleurs-VPN')}} <i class="fa fa-angle-down"></i></button>
  <div id="myDropdown1" class="d_content d_mobile_1">

    <a href="{{ route('vpn.index') }}">Tous les VPN</a>

    <a href="{{ route('vpn.windows') }}">Windows</a>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68151319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档