如何使用jquery或css创建滑动导航?

时间:2014-07-11 05:09:48

标签: jquery css html5 css3

所以我想创建一个菜单,当悬停时有一个类似于This website的滑动。任何人对我如何完成这个有任何想法?

<nav>
    <ul>
        <li>Menu 1
            <ul>
                <li>Sub 1</li>
                <li>Sub 2</li>
                <li>Sub 3</li>
            </ul>
        </li>
        <li>Menu 2</li>
        <li>Menu 3</li>
    </ul>
</nav>

1 个答案:

答案 0 :(得分:0)

您可以尝试this

HTML

<nav class="nav ">
    <ul class="clearfix">
        <li><a href="">Menu 1</a>
            <ul>
                <li><a href="">Sub 1</a></li>
                <li><a href="">Sub 2</a></li>
                <li><a href="">Sub 3</a></li>
              <li><a href="">Sub 1</a></li>
                <li><a href="">Sub 2</a></li>
                <li><a href="">Sub 3</a></li>
            </ul>
        </li>
        <li><a href="">Menu 2</a>
      <ul>
                <li><a href="">Sub 1</a></li>
                <li><a href="">Sub 2</a></li>
                <li><a href="">Sub 3</a></li>
            </ul>
      </li>
        <li><a href="">Menu 3</a>
      <ul>
                <li><a href="">Sub 1</a></li>
                <li><a href="">Sub 2</a></li>
                <li><a href="">Sub 3</a></li>
            </ul></li>
    </ul>
</nav>

CSS

    * {
  margin: 0;
  padding: 0;
}
.clearfix:after {
  clear: both;
  content: " ";
  display: block
}
ul {
  list-style: none;
  width: 100%;
  background: #ccc;
}
.nav> ul > li {
  float: left;
  position: relative;
}
.nav > ul > li > a {
  position: relative;
  background: #ccc;
  z-index: 1;
  display: block;
  padding: 5px 80px;
}
a {
  text-decoration: none;
  padding: 5px;
}
.nav ul ul {
  position: absolute;
  left: 0;
  top: -300px;
  width: 150px;
  -webkit-transition: top 0.6s ease-in-out;
  -moz-transition: top 0.6s ease-in-out;
  -ms-transition: top 0.6s ease-in-out;
  -o-transition: top 0.6s ease-in-out;
  transition: top 0.6s ease-in-out;
  background: #ddd;

}
.nav li:hover ul {
  top: 29px;
}