gpt4 book ai didi

css - React Bulma 移动导航栏未按预期工作

转载 作者:行者123 更新时间:2023-12-04 17:17:04 25 4
gpt4 key购买 nike

当我单击按钮切换移动导航栏时,它不起作用。我正在使用 Bulma css 框架进行 react 。这是 React 导航栏组件:

onst Header = (props) => {
const dispatch = useDispatch()
const { loginUser, isAuthenticated, history, errors } = props;

const dropdownRef = useRef(null);
const [isActive, setIsActive] = useDetectOutsideClick(dropdownRef, false);
const [isMobileActive, setisMobileActive] = useState(false);
const onClick = () => setIsActive(!isActive);

const onLogout = () => {
dispatch(logout())
}

return (
<nav className="navbar" role="navigation" aria-label="main navigation">
<div className="navbar-brand">
<a className="navbar-item" href="https://bulma.io">
<img
src="https://bulma.io/images/bulma-logo.png"
width="112"
height="28"
/>
</a>

<a
onClick={() => {
setisMobileActive(!isMobileActive)
}}
role="button"
className={`navbar-burger burger ${isActive ? "is-active" : ""}`}
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>

<div id="navbarBasicExample" className="navbar-menu">
<div className="navbar-end">
<a className="navbar-item">Dashboard</a>

<div
onClick={onClick}
ref={dropdownRef}
className={`navbar-item has-dropdown ${
isActive ? "is-active" : ""
}`}
>
<a className="navbar-link">Account</a>

<div className="navbar-dropdown is-right">
<a className="navbar-item">Account settings</a>
<a className="navbar-item">Set Job filters</a>
<a className="navbar-item">Report an issue</a>

<a className="navbar-item" onClick={onLogout}>Log out</a>
</div>
</div>
</div>
</div>
</nav>
);
};

带下拉菜单的最底部是桌面导航栏。移动切换菜单缺少什么。我该如何解决?谁我点击切换按钮没有任何反应。

最佳答案

我不熟悉 React,但在 bulma 方面,您需要在 navbar-burger 和目标 上切换类 is-active >导航栏菜单
Bulma navbar documentation中有实现示例,我个人正在使用完美运行的 jQuery 实现:

 $(document).ready(function() {

// Check for click events on the navbar burger icon
$(".navbar-burger").click(function() {

// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");

});
});

但如果您需要,文档中还有一个 Vanilla Javascript 实现。

关于css - React Bulma 移动导航栏未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68457400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com