javascript - Div 隐藏,直到我单击文本/按钮,出现,然后当我单击另一个时,它消失,另一个可见

标签 javascript jquery html css

<分区>


关闭 8 年前

我该怎么做?这是我目前所拥有的:

<!DOCTYPE HTML>

<html>
  
<style>
  @charset 'UTF-8';
  @import url("http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,600");
  body {
    background: #fff;
  }
  body,
  input,
  textarea,
  select {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 19pt;
    font-weight: 300;
    line-height: 1.75em;
    color: #888;
  }
}
header {
  margin: 0 0 2em 0;
}
header > p {
  margin: 1em 0 0 0;
}
a {
  text-decoration: none;
  color: inherit;
}
a:hover {
  color: #E27689;
  border-bottom-color: rgba(255, 255, 255, 0);
}
.image.avatar48 img {
  width: 70px;
  height: 60px;
}
#header {
  position: fixed;
  top: 0;
  left: 0;
  width: 375px;
  height: 100%;
  color: #fff;
  background: #222629;
  box-shadow: inset -0.25em 0 0.25em 0 rgba(0, 0, 0, 0.1);
  text-align: right;
}
#logo {
  position: relative;
  margin: 1.75em 1.5em 1.5em 1.5em;
  min-height: 48px;
  cursor: default;
}
#logo h1 {
  position: relative;
  color: #fff;
  font-weight: 600;
  font-size: 1em;
  line-height: 1em;
}
#logo p {
  position: relative;
  display: block;
  font-size: 0.6em;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.25em;
  margin: 0.5em 0 0 0;
}
#logo .image {
  position: absolute;
  left: 0;
  top: 0;
}
#nav ul li a {
  display: block;
  padding: 0.5em 1.5em 0.5em 1.5em;
}
#main > section {
  margin: 0;
  overflow: hidden;
  padding: 0;
  text-align: center;
  position: absolute;
  top: 30%;
  left: 50%;
}
.portfolio {
  position: relative top: 20%;
  left: 50%;
  visibility: hidden
}
</style>

<head>
  <title>Ryan H</title>
</head>

<body>

  <div id="header" class="skel-layers-fixed">

    <div class="top">

      <!-- Logo -->
      <div id="logo">
        <span class="image avatar48"><img src="http://i.imgur.com/r3HkBkB.jpg" alt="" /></span>
        <h1 id="title">Ryan Ho</h1>
        <p>13 years old</p>
      </div>

      <nav id="nav">

        <ul>
          <li><a href="#top" id="top-link"><span class="icon fa-home">Intro</span></a>
          </li>

          <li><a href="#about" id="about-link"><span class="icon fa-user">About Me</span></a>
          </li>

          <li><a href="#portfolio" id="portfolio-link"><span class="icon fa-user">Stuff</span></a>
          </li>

        </ul>
      </nav>

    </div>

  </div>

  <!-- Main -->
  <div id="main">

    <!-- Intro -->
    <section id="top" class="one dark cover">
      <div class="container">

        <header>
          <h2 class="alt">I am Ryan H.</h2>
        </header>

      </div>
    </section>
    <!-- About Me -->
    <section id="about" class="two">
      <div class="container">

        <header>
          <h2>About Me</h2>
        </header>

        <p>Site In Progress</p>

      </div>
    </section>

    <section id="portfolio" class="three">
      <div class="container">

        <header>
          <h2>Stuff</h2>
        </header>

        <p>This is where I would put my stuff, if I had any.</p>
      </div>
    </section>
  </div>
</body>

</html>

我必须使用 jQuery 还是 Javascript?如果是这样,它是什么?我卡住了。

最佳答案

使用 jQuery...

http://jsfiddle.net/v6kxc2uk/

<div id="1" style="display: none;">some text</div>
<div id="2" >some more text</div>
<button linkto="1">1</button>
<button linkto="2">2</button>

$('button').on('click', function(){

    $('div').hide();
    $('div#'+$(this).attr('linkTo')).show();

});

关于javascript - Div 隐藏,直到我单击文本/按钮,出现,然后当我单击另一个时,它消失,另一个可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28535196/

上一篇:html - 如何用纯CSS创建文字描边和三 Angular 形?

下一篇:html - 页 footer 分与使用 CSS 的其他分区部分重合

相关文章:

javascript - Angular 依赖注入(inject) - 无法实例化工厂/未定义的工厂

javascript - 从约束列表中生成所有可能的对象

javascript - 按键事件未在移动设备上运行

javascript - 为什么 jquery 的 .load() 会忽略 &lt;script&gt;?

javascript - 输入的值即使不符合要求也被发送

javascript - 为什么当我们用 “--enable-precise-memory-info” 打开 Chrome 时 usedJSHeapSize 总是增加,即使我没有在页面中做任何事情?

Javascript RegExp 仅允许某些位置出现某些字符

jquery - 在 jQuery 中,一个按钮可以工作,而另一个则不行。

javascript - 处理 SVG 图像的属性

css - 没有为节标签设置边距