javascript - 使主要 div 出现和消失的导航栏

标签 javascript html css

我试图让主页 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:larsmulleneers@hotmail.nl">Larsmulleneers@hotmail.nl</a> </p>

最佳答案

使用

 document.getElementsByClassName

返回一个数组而不是元素,所以你不能在没有索引号的情况下更改元素 试试这个

document.getElementsByClassName('home')[0].style.display = 'none';
document.getElementsByClassName('about')[0].style.display = 'block'

关于javascript - 使主要 div 出现和消失的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46200481/

相关文章:

javascript - 如何使用 SCSS、PurgeCSS 和 LiveServer 设置自定义 ESBuild?

javascript - 如果我使用单独的 html/css 页面,如何创建模态弹出效果?

javascript - 操作 HTML 中的路径元素

javascript - 在 onload 函数中提交 HTML 表单

html - 填充剩余空间(CSS)

css - ui-g-12 ui-lg-12 ui-md-12 是什么意思?

javascript - 在从查找返回之前等待 mongo 写入

javascript - Angular 2 : Changing static parts of the view according to path

javascript - jquery .click() 并不完成与实际单击链接相同的过程;需要单击实际链接才能使流程正常运行

html - 灵活居中的 SVG