我想讓主div不見了,關於頁面出現,但由於某種原因,我無法讓它工作。這是一個導航欄,如果我能得到一個工作,我可以讓他們都這麼認爲幫助。當我按關於段落並使關於div出現時,我需要回家消失。我希望有人能幫助我,我已經搜索了很多,它不會工作。導航欄製作主div出現和消失
// page movement
function goA() {
document.getElementsByClassName("home").style.display = "none";
document.getElementsByClassName("about").style.display = "block";
}
.home {
background: #4f4f4f;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
position: absolute;
}
.backgroundpic {
background-image: url("http://cdn.wallpapersafari.com/58/58/hlVdYW.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 93.7%;
margin-left: 50px;
margin-right: 50px;
margin-bottom: 30px;
margin-top: 30px;
overflow: hidden;
}
.about {
font-family: Open sans;
color: #fff;
font-size: 150%;
text-align: left;
display: inline-block;
cursor: default;
}
.about a {
text-decoration: none;
color: #fff;
border-bottom: 2px solid rgba(225, 225, 225, .7);
}
.about {
font-family: Open sans;
color: #fff;
font-size: 150%;
cursor: default;
position: relative;
padding: 0;
margin-left: 50%;
margin-right: 10%;
margin-top: 18.4%;
text-align: left;
display: none;
}
<!-- home div -->
<div class="home">
<div class="backgroundpic">
<div class="picgradiant">
<!-- navigation button -->
<div class="navigation">
<div class="navloc">
<p class="loc" onclick="goW()">WebDesign</p>
<p class="loc" onclick="goGr()">Photography</p>
<p class="loc" onclick="goS()">SketchUp</p>
<p class="loc" onclick="goSh()">Photoshop</p>
<p class="loc" onclick="goA()">About</p>
<p class="loc" onclick="goH()">Home</p>
</div>
<div class="stripes">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
</div>
<!-- text about myself -->
<div class="totalheader">
<div class="headtext">
<p class="header1">Sup, I'm Lars.</p>
<p class="text1">I do things!</p>
</div>
<p class="buttonhead">click to lear more</p>
</div>
</div>
</div>
</div>
<!-- about div -->
<div class="about">
<p>I like to explore different programs and try out as many things as I can. I do this so I can make an informed, good and fun career choice! A lot of projects start with me and my friend talking and getting an idea. Eventually we try to make it happen,
but sometimes help altogether and sometimes us work together. my goal at the moment is the become a game developer, but I am also interested in game design and internet security. I am not sure what the future holds for me, but in the end, I hope that
I'll have a fun job. If you want more info you can contact me at: <a href="mailto:[email protected]">[email protected]</a> </p>
'document.getElementsByClassName'返回結果的數組。即使只有1個結果,您仍然需要通過索引訪問它。嘗試'document.getElementsByClassName(「home」)[0] .style.display =「none」;' – DillGromble