我试图通过单击导航按钮隐藏和显示 div 来将我的网站限制在一个页面上。我遇到的问题是,除非我按下第一个按钮,否则其他按钮将不起作用。如果我快速向两个导航按钮发送垃圾邮件,我还有另一个问题是同时显示两个 div。想要确保不会发生这种情况,以防观众点击按钮感到高兴。
我对 Javascript 还是很陌生,但对大部分基础知识都非常了解。任何帮助,将不胜感激。谢谢。
我正在使用的 HTML 部分:
<!-- Beginning of navigationBar ---->
<div id = "navigationBar">
<!-- Beginning of logoBox ---->
<div id ="logoBox">
</div>
<!-- End of logoBox ---->
<!-- Beginning of menuBar ---->
<div id ="menuBar">
<a href= "#" id="home">Home</a>
<a href= "#" id="designers">Designers</a>
<a href= "#" id="elements">Elements</a>
<a href= "#" id= "sample">Your Sample Page</a>
<a href= "#" id="contact">Contact Us</a>
</div>
<!-- End of menuBar ---->
</div>
<!-- End of navigationBar ---->
<!-- Beginning of mainContent ---->
<div id="mainContent">
<!-- Begining of Intro Page --->
<div id= "Intro"> Intro Page content goes here.
</div>
<!-- End of Intro Page --->
<!-- Begining of Home Page --->
<div id= "Home">Home page content goes here.
</div>
<!-- End of Home Page --->
<!-- Begining of Designers Page --->
<div id= "Designers"> Designers page content goes here.
</div>
<!-- End of Designers Page --->
<!-- Begining of Elements Page --->
<div id= "Elements"> Elements page content goes here.
</div>
<!-- End of Elements Page --->
<!-- Begining of Sample Page --->
<div id= "Sample">Sample page content goes here.
</div>
<!-- End of Sample Page --->
<!-- Begining of Contact Page --->
<div id= "Contact">Contact page content goes here.
</div>
<!-- End of Contact Page --->
已添加和使用的 CSS 位:
#menuBar {
padding:5px;
}
#menuBar > a{
font-family:Arial, Helvetica, sans-serif;
font-size:17px;
border:#CCC 1px solid;
background:#FFF;
padding: 5px 10px;
color: #999;
margin-right: 5px;
text-decoration: none;
border-radius: 3px;
-webkit-transition: background 0.3s linear 0s, color 0.3s linear 0s;
-moz-transition: background 0.3s linear 0s, color 0.3s linear 0s;
-ms-transition: background 0.3s linear 0s, color 0.3s linear 0s;
-o-transition: background 0.3s linear 0s, color 0.3s linear 0s;
transition: background 0.3s linear 0s, color 0.3s linear 0s;
}
#menuBar > a:hover{
background: #000;
color: #FFF;
}
#mainContent {
}
#socialMediaBar {
background:#000;
width: 100%;
height: 30px;
}
#copyRight {
}
#Intro {
display:none;
}
#Home {
display:none;
}
#Designers {
display:none;
}
#Elements {
display:none;
}
#Sample {
display:none;
}
我的javascript失败代码:
window.onload=function(){
$('#Intro').fadeIn("Slow")};
$("#home").click(function(){
$('#Home').fadeIn("Slow");
if($('#Home').is(':visible')){
$('#Designers, #Elements, #Sample, #Contact, #Intro').hide();}
$("#designers").click(function(){
$('#Designers').fadeIn("Slow");
if($('#Designers').is(':visible')){
$('#Home, #Elements, #Sample, #Contact, #Intro').hide()};
});
$("#elements").click(function(){
$('#Elements').fadeIn("Slow");
if($('#Elements').is(':visible')){
$('#Designers, #Home, #Sample, #Contact, #Intro').hide()};
});
$("#sample").click(function(){
$('#Sample').fadeIn("Slow");
if($('#Sample').is(':visible')){
$('#Designers, #Home, #Elements, #Contact, #Intro').hide()};
});
$("#contact").click(function(){
$('#Contact').fadeIn("Slow");
if($('#Contact').is(':visible')){
$('#Designers, #Home, #Sample, #Elements, #Intro').hide()};
});
});