使切换效果消失

时间:2018-09-20 17:08:54

标签: html css navigation

一个切换开关出现在width:912px处,通过单击一个切换开关(最大宽度:912px),您会触发垂直菜单的出现,但是当您将其变宽时,该切换开关就会消失并且会出现一个水平菜单,但是垂直菜单仍然存在(fiddle)。

function onScroll() {
  $(window).on("scroll", function() {
    if ($(window).scrollTop()) {
      $('nav').addClass('add');
    } else {
      $('nav').removeClass('add');
    }
  })
}

function clickScroll() {
  $("#toggle").click(function() {
    $(this).toggleClass("on");
    $("#content").toggleClass("click");
    $("#place").toggleClass("on");
  })
}

clickScroll();
onScroll();
* {
  margin: 0px;
  padding: 0px;
}

nav {
  width: 100%;
  height: 60px;
  font-family: 'Quicksand', sans-serif;
  background-color: #7b2e1e;
  position: fixed;
  top: 0;
  z-index: 999;
}

/* #7b2e1e*/

#wrapper {
  width: 80%;
  height: 100%;
  margin: 0px auto;
  position: relative;
}

.logo {
  width: 323px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.logo h2 {
  width: 97px;
  border: 1px solid black;
  padding: 7px;
  text-transform: uppercase;
}

ul {
  width: 70%;
  display: block;
  list-style: none;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  text-align: right;
}

li {
  display: inline-block;
  margin: 9px;
  position: relative;
  margin-left: 25px;
}

a {
  text-decoration: none;
  color: black;
  transition: all ease-in-out 0.2s;
  text-transform: uppercase;
}

a:hover {
  color: red;
}


/*nav a::before{
	content: '';
	display: block;
	height: 4px;
	background-color: black;
	position:absolute;
	top:-30px;
	width:0%;
}

nav a:hover::before{
	width:100%;
	transition: all ease-in-out 0.2s;
}*/

a.exclusive {
  background-color: #000;
  color: #FFF;
  padding: 4px;
  border-radius: 5px;
}

a.exclusive:hover {
  transition: all ease-in-out 0.2s;
  background-color: white;
  color: black;
}

#toggle {
  width: 25px;
  height: 25px;
  float: right;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  visibility: hidden;
  cursor: pointer;
  border: 1px solid black;
}

#toggle .line {
  width: 100%;
  height: 3px;
  background-color: #000;
  margin: 3px auto;
  transition: ease-out 0.5s;
}

#toggle.on #one {
  transform: rotate(45deg) translateX(1px) translateY(4px);
}

#toggle.on #two {
  opacity: 0;
}

#toggle.on #three {
  transform: rotate(-45deg) translateX(5px) translateY(-8px);
}

#content {
  position: relative;
  top: 0px;
  width: 70%;
  margin: 5px auto;
  top: 85px;
}

#content.click {
  top: 10px;
}

main {
  width: 100%;
}

p {
  width: 87%;
  padding: 20px;
  margin: 10px auto;
  word-spacing: 4px;
  line-height: 25px;
}

#content main h2 {
  text-align: center;
  margin-top: 13px;
}

p::first-letter {
  font-size: 25px;
  font-weight: 700;
}

#place {
  width: 100%;
  height: 20vh;
  position: relative;
  float: left;
  border: 1px solid black;
  border-top: 2px solid black;
}

#resize {
  position: absolute;
  left: 0;
  width: auto;
  text-align: left;
}

#resize li {
  display: block;
}

#place {
  width: 100%;
  background-color: #7b2e1e;
  border-top: 1px solid black;
  text-align: right;
  position: relative;
  height: 180px;
  display: none;
  transition: ease-in 0.9s;
  z-index: 999;
}

#resize {
  display: block;
  position: absolute;
  left: 7%;
  width: 80%;
  height: 100% border:13px solid yellow;
  padding: 300px 0;
  transition: ease-in 0.9s;
}

#place #resize li {
  margin-top: 13px;
}

#place.on {
  display: block;
  transition: ease-in 0.5s;
}

@media screen and (max-width: 912px) {
  #wrapper ul {
    display: none;
  }
  #toggle {
    visibility: visible;
    cursor: pointer;
  }
}

@media screen and (min-width:912px) {
  #place {
    display: none;
  }
}
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous">
</script>

<!-- Navigationsbar -->
<nav>

  <div id="wrapper">

    <div class="logo">

      <h2> Navbar </h2>

    </div>

    <ul>
      <li><a href="#"> Home </a></li>
      <li><a href="#"> About </a></li>
      <li><a href="#"> Pricings </a></li>
      <li><a href="#"> Blog </a></li>
      <li><a href="#" class="exclusive"> Contact </a></li>
    </ul>

    <div id="toggle">
      <div id="one" class="line"> </div>
      <div id="two" class="line"> </div>
      <div id="three" class="line"> </div>
    </div>

  </div>

  <div id="place">
    <ul id="resize">
      <li><a href="#"> Home </a></li>
      <li><a href="#"> About </a></li>
      <li><a href="#"> Pricings </a></li>
      <li><a href="#"> Blog </a></li>
      <li><a href="#"> Contact </a></li>
    </ul>
  </div>

</nav>

<div id="content">
  <main>

    <h2> Ueberschrift </h2>

    <p>

      What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
      specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
      recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
      text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was
      popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy
      text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five
      centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
      Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
      took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
      Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,
      remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What
      is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
      specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
      recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
      text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was
      popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy
      text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five
      centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
      Aldus PageMaker including versions of Lorem Ipsum. What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
      took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    </p>

  </main>

</div>

0 个答案:

没有答案