[英]How do I creat a navbar that when clicked it opens on the same page?
Create the small window as it's own div: 创建小窗口,因为它是自己的div:
<div id="myID"> This content will show when I click the navbar</div>
Add the following CSS: 添加以下CSS:
#myID{
display: none;
}
Then use some script to show/hide the element: 然后使用一些脚本来显示/隐藏元素:
$(document).ready(function(){
// change #nav to whatever the ID of the nav element is.
$('#nav').on('click', function(){
// show/hide pop up on click
$('#myID').toggle();
});
});
You can create a Navbar like this. 您可以像这样创建导航栏。 This is the only dummy. 这是唯一的假人。 In given image, they have one fix element and when you click on nav element according to that they are updating the content of that element. 在给定的图像中,它们具有一个fix元素,并且当您单击nav元素时,它们将更新该元素的内容。
$('#myNav').find('li a').click(function (e) { $('li.active').removeClass('active'); $(this).parent('li').addClass('active'); $('#main').html($(this).html()); });
ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #567; } li { float: left; } li a { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover:not(.active) { background-color: #ccc; } .active { background-color: #ccc; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul id="myNav"> <li class="active"><a href="javascript:void(0);">Home</a></li> <li><a href="javascript:void(0);">Service</a></li> </ul> <div id="main"> Home </div>
It will help you to create a nav bar. 它将帮助您创建导航栏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.