我想让语言菜单在桌面上时用作下拉菜单,而在移动设备上保持非活动下拉菜单。
在移动设备上单击后,它应该在下拉菜单中显示选项,保留在汉堡包菜单中。
语言菜单:
https://i.stack.imgur.com/bik75.png
&&
https://i.stack.imgur.com/waYAk.png
我希望它在桌面上做什么:
https://i.stack.imgur.com/OD5zn.png
我已经使用 javascript 代码使菜单在桌面上可点击,但在移动设备上菜单行为奇怪。
我希望看到下拉菜单在单击桌面时工作,并且当我单击桌面上的任何其他位置时,它会关闭,而不仅仅是当我单击菜单本身时。
在移动设备上,菜单看起来很奇怪,而不是在单击之前被停用。
JSFiddle -> <script async src="//jsfiddle.net/jkuwg3ac/embed/"></script>
有一种更好的方法可以在没有JavaScript的情况下使用Bulma创建语言菜单。
语言菜单 HTML:
<div class="select">
<select>
<option selected>English</option>
<option>Italian</option>
<option>Arabic</option>
</select>
</div>
这是你使用我的想法的项目:
document.addEventListener('DOMContentLoaded', () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(el => {
el.addEventListener('click', () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test!</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>
<body>
<nav class="navbar has-text-centered" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navMenu">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
</div>
<div class="navbar-end">
<div class="select">
<select>
<option selected>English</option>
<option>Italian</option>
<option>Arabic</option>
</select>
</div>
</div>
</div>
</nav>
</body>
</html>