ナビゲーション ボタンをクリックして div を隠したり表示したりして、サイトを 1 ページに制限しようとしています。私が抱えている問題は、最初のボタンを押さない限り、他のボタンが機能しないことです。また、2 つのナビゲーション ボタンをすばやくスパムすると、2 つの 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()};
});
});