响应式动画导航

时间:2017-11-17 10:26:45

标签: html css navigation responsive

我有codyhouse的css动画教程非常好。我们编写了这个导航菜单,我想进一步调整一下我的喜欢。

我想我试图在大于640像素的屏幕上显示导航链接,并使其在所有其他屏幕尺寸上不可见(如此当前状态)。

Codepen



var navTrigger = document.getElementsByClassName('nav-trigger')[0],
    body = document.getElementsByTagName('body')[0];

navTrigger.addEventListener('click', toggleNavigation);

function toggleNavigation(event) {
  event.preventDefault();
  body.classList.toggle('nav-open');
}

*, *::after, *::before {
  box-sizing: border-box;
}
body {
  font-family: sans-serif;
  line-height: 1;
  margin: 0;
  width: 100%;
  height: 100%;
  background: #333;
}

main {
  position: relative;
  z-index: 1;
  height: 100vh;
  overflow: hidden;
  transition: transform .5s;
  box-shadow: 0 0 50px #000;
}

.nav-open main {
  transform: scale(.8)
}

.intro {
  height: 100vh;
  width: 100%;
  display: table;
  background: #f3f3f3;
}

h1 {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  font-size: 45px;
  color: #ddd;
}

.nav-trigger {
  position: fixed;
  z-index: 4;
  top: 40px;
  right: 40px;
  height: 44px;
  width: 44px;
  
  overflow: hidden;
  color: transparent;
  white-space: nowrap;
  text-indent: 100%;
}
.nav-trigger span,
.nav-trigger span::before,
.nav-trigger span::after {
  position: absolute;
  height: 4px;
  width: 36px;
  background: #111; 
  transition: all .3s;
}


.nav-trigger span {
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
}

.nav-trigger span::before,
.nav-trigger span::after {
	content: '';
	top: 0;
	left: 0;
}

.nav-trigger span::before {
	transform: translateY(-12px);
}

.nav-trigger span::after {
	transform: translateY(12px);
}

.nav-trigger:hover span,
.nav-trigger:hover span::before,
.nav-trigger:hover span::after {
  background: #888;
}

.nav-open .nav-trigger span {
  background: transparent;
}

.nav-open .nav-trigger span::before,
.nav-open .nav-trigger span::after {
  background: #888;
}

.nav-open .nav-trigger span::before {
  transform: rotate(-45deg);
}
.nav-open .nav-trigger span::after {
  transform: rotate(45deg);
}

.overlay {
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: #333;
  opacity: 0;
  visibility: hidden;
  transition: all .5s;
}

.nav-open .overlay {
  opacity: .5;
  visibility: visible;
}

.nav-container {
  position: fixed;
  z-index: 3;
  top: 0;
  right: 0;
  height: 100%;
  width: 100%;
  padding: 3em 3.5em;
  background: #343434;
  overflow: auto;
  transform: translateZ(0);
  transform: translateY(-100%);
  transition: transform .5s cubic-bezier(.07,.23,.34,1);
}
.nav-open .nav-container {
  transform: translateX(0);
}


.nav {
  list-style: none;
  padding: 0;
}
.nav a {
  display: block;
  padding: .6em 0;
  font-size: 30px;
  font-family: bold;
  font-family: sans-serif;
  text-decoration: none;
  color: #747474;
  transform: translateZ(0);
}

.nav-open .nav a {
  animation: slide-in .4s .2s backwards;
}
.nav-open .nav li:nth-of-type(2) a {
  animation-delay: .3s;
}
.nav-open .nav li:nth-of-type(3) a {
  animation-delay: .4s;
}

.nav-open .nav li:nth-of-type(4) a {
  animation-delay: .5s;
}

.nav-open .nav li:nth-of-type(5) a {
  animation-delay: .6s;
}

.nav li {
  text-align: center;
}

@keyframes slide-in {
  0% {
    opacity: 0;
    transform: translateY(-20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}


@media only screen and (min-width : 640px) {
  
/*   .nav-trigger {
    visibility: hidden;
  } */
/*   .nav li {
    display: inline-block;
    z-index: 60;
  } */
  
}

<body>
<a href="#navigation" class="nav-trigger">
  Menu<span></span>
</a>

<main>
  <section class="intro">
    <h1>Final Project</h1>
  </section>
</main>

<nav class="nav-container" id="navigation">
  <ul class="nav">
    <li><a href="#0">Work</a></li>
    <li><a href="#0">About</a></li>
    <li><a href="#0">Contact</a></li>
  </ul>
</nav>

<div class="overlay"></div>
  
</body>
&#13;
&#13;
&#13;

0 个答案:

没有答案