所以我有这个侧栏,我想切换它的行为。 而不是像这样关闭:
我希望在网站启动时保持打开状态:
这是javascript
<script type="text/javascript">
$(function() {
$('.navbar-toggler').on('click', function(event) {
event.preventDefault();
$(this).closest('.navbar-minimal').toggleClass('open');
})
});
</script>
和Html
<nav class="navbar navbar-fixed-left navbar-minimal animate" role="navigation" id="sidebar-1">
<div class="navbar-toggler animate">
<span class="menu-icon"></span>
<p id="menutab">Menu</p>
</div>
<ul class="navbar-menu animate">
<li class="dropdown" id="dropdown-nav">
<a href="#" class="animate dropdown-toggle" data-toggle="dropdown">
<span class="desc animate" style="font-family: 'Roboto Condensed', sans-serif;">Top 5 Events</span>
<span class="mini-icon"><img src="Images/ps/Events.png" id="mini-icon"></span>
</a>
<ul class="dropdown-menu" id="events">
<iframe src="Php/events.php" id="iframe" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto">
<p>Your browser does not support iframes.</p>
</iframe>
</ul>
</li>
答案 0 :(得分:1)
<nav class="navbar navbar-fixed-left navbar-minimal animate"
转到html标记中的上一行,然后添加类“打开”,如下所示
<nav class="navbar navbar-fixed-left navbar-minimal animate open"
因此默认情况下会打开它。
答案 1 :(得分:0)
<script type="text/javascript">
$(function () {
$(this).closest('.navbar-minimal').toggleClass('open');
});
</script>
答案 2 :(得分:0)
将类打开添加到导航栏菜单中,通过该菜单显示打开,当您点击菜单时,它会复制元素ul.navbar-menu
$(".navbar-toggler").click(function () {
$(".navbar-menu").slideToggle();
});