简体   繁体   English

移动设备上的下拉菜单不会在第二次点击时隐藏

[英]Dropdown menu on mobile doesn't hide on second click

I'm trying to put this dropdown menu on my website:我正在尝试将此下拉菜单放在我的网站上:

*https://codepen.io/sean_codes/pen/WdzgdY*

My website is totally mobile-friendly.我的网站完全适合移动设备。

When I click to open the menu on the phone, it opens normally, but when I click the second time, it doesn't close.在手机上点击打开菜单时,它可以正常打开,但是当我第二次点击时,它并没有关闭。 It closes only when I click away.只有当我点击离开时它才会关闭。

How do I put that menu to close when I click the menu icon a second time?当我再次单击菜单图标时,如何关闭该菜单?

It is best to avoid the usage of hover on mobile devices.最好避免在移动设备上使用hover You will first have to check if the browser supports it via @media and create some sort of fallback in case it does not.您首先必须通过@media 检查浏览器是否支持它,并在不支持的情况下创建某种回退。
Try using input html element and set the type to checkbox for your dropdown buttons and toggle your dropdown with checked .尝试使用input html 元素并将下拉按钮的类型设置为checkbox ,并使用checked切换下拉菜单。
No need to use javascript for this. 无需为此使用 javascript。

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

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