【问题标题】:How to change the navigation bar animation in the opposite direction?如何改变导航栏动画反方向?
【发布时间】:2019-09-11 02:19:32
【问题描述】:

所以,我正在创建一个网站设计,我想将我的导航栏位置从右上更改为左上,并且想将导航栏打开动画更改为相反的方向。 我的意思是整个导航栏都在右上角。

我在 CSS 和 Web 开发方面没有太多经验,所以请帮助我,我的学校项目需要这个。 谢谢大家! 代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
     
    <style>
    
body {
  
    font-family: 'Roboto Condensed', sans-serif;  
  font-size: 16px;
    overflow: hidden;
    text-transform: uppercase;
    font-weight: bold;
}
.menu {
  height: 70px;
  width: 70px;
  right: 70px;
  top: 20px;
  text-align: center;
  position: absolute;
  background: #f463c3;
  overflow: hidden;
  transition: all 0.2s ease;
  z-index: 999;
}
.menu.active {
  width:85%;
  transition:width 0.3s;
   -webkit-transition:width .3s;
   -moz-transition: width 0.3s;
    
}
.menu.active .menuContent * {
  opacity: 1;
}
.menu.active span i:nth-child(1) {
  transform: rotate(-45deg) translate(-50%, -50%);
  top: 50%;
}
.menu.active span i:nth-child(2) {
  transform: translateX(-100px);
  opacity: 0;
}
.menu.active span i:nth-child(3) {
  transform: rotate(45deg) translate(-50%, -50%);
  top: 50%;
}
.menu span {
  width: 70px;
  height: 70px;
  position: absolute;
  right: 0;
  cursor: pointer;
  background: #f463c3;
  z-index: 1;
}
.menu span i {
  position: absolute;
  transform-origin: 50% 50%;
  width: 45%;
  height: 2px;
  left: 0;
  right: 0;
  margin: auto;
  background-color: #ccc;
  transition: transform 0.3s ease, opacity 0.1s ease 0.1s;
}
.menu span i:nth-child(1) {
  top: 40%;
}
.menu span i:nth-child(2) {
  top: 50%;
}
.menu span i:nth-child(3) {
  top: 60%;
}
.menu .menuContent {
  position: absolute;
  width: 100%;
  height: 100%;
  line-height: 40px;
  right: 0px;
  text-align: center;
}
.menu .menuContent * {
  opacity: 0;
}
.menu .menuContent ul li {
  display: inline-block;
  margin-left: 50px;
  margin-right: 50px;
  color: #2d3235;
  transition: opacity 0.3s ease 0.3s;
  cursor: pointer;
  position: relative;
}
.menu .menuContent ul li:hover:before {
  opacity: 0.8;
  top: 13px;
  left: 20px;
}
.menu .menuContent ul li:hover:after {
  opacity: 0.8;
  bottom: 13px;
  left: -20px;
}
        
    </style>
</head>
<body>
    <div class='menu'>
  <span class='toggle'>
    <i></i>
    <i></i>
    <i></i>
  </span>
  <div class='menuContent'>
    <ul>
      <li>Home</li>
      <li>About</li>
      <li>Contact</li>
      <li>Testimonial</li>
      <li>About us</li>
    </ul>
  </div>
</div>
 
<script
  src="https://code.jquery.com/jquery-3.3.1.js"
   ></script>
<script>
    $('.toggle').on('click', function() {
	$('.menu').toggleClass('active');
});
    
</script>
</body>
</html>

【问题讨论】:

    标签: javascript jquery html css web


    【解决方案1】:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
         
        <style>
        
    body {
      
        font-family: 'Roboto Condensed', sans-serif;  
      font-size: 16px;
        overflow: hidden;
        text-transform: uppercase;
        font-weight: bold;
    }
    .menu {
      height: 70px;
      width: 70px;
      left: 70px;
      top: 20px;
      text-align: center;
      position: absolute;
      background: #f463c3;
      overflow: hidden;
      transition: all 0.2s ease;
      z-index: 999;
    }
    .menu.active {
      width:85%;
      transition:width 0.3s;
       -webkit-transition:width .3s;
       -moz-transition: width 0.3s;
        
    }
    .menu.active .menuContent * {
      opacity: 1;
    }
    .menu.active span i:nth-child(1) {
      transform: rotate(-45deg) translate(-50%, -50%);
      top: 50%;
    }
    .menu.active span i:nth-child(2) {
      transform: translateX(-100px);
      opacity: 0;
    }
    .menu.active span i:nth-child(3) {
      transform: rotate(45deg) translate(-50%, -50%);
      top: 50%;
    }
    .menu span {
      width: 70px;
      height: 70px;
      position: absolute;
      left: 10px;
      cursor: pointer;
      background: #f463c3;
      z-index: 1;
    }
    .menu span i {
      position: absolute;
      transform-origin: 50% 50%;
      width: 45%;
      height: 2px;
      left: 0;
      right: 0;
      margin: auto;
      background-color: #ccc;
      transition: transform 0.3s ease, opacity 0.1s ease 0.1s;
    }
    .menu span i:nth-child(1) {
      top: 40%;
    }
    .menu span i:nth-child(2) {
      top: 50%;
    }
    .menu span i:nth-child(3) {
      top: 60%;
    }
    .menu .menuContent {
      position: absolute;
      width: 100%;
      height: 100%;
      line-height: 40px;
      right: 0px;
      text-align: center;
    }
    .menu .menuContent * {
      opacity: 0;
    }
    .menu .menuContent ul li {
      display: inline-block;
      margin-left: 50px;
      margin-right: 50px;
      color: #2d3235;
      transition: opacity 0.3s ease 0.3s;
      cursor: pointer;
      position: relative;
    }
    .menu .menuContent ul li:hover:before {
      opacity: 0.8;
      top: 13px;
      left: 20px;
    }
    .menu .menuContent ul li:hover:after {
      opacity: 0.8;
      bottom: 13px;
      left: -20px;
    }
            
        </style>
    </head>
    <body>
        <div class='menu'>
      <span class='toggle'>
        <i></i>
        <i></i>
        <i></i>
      </span>
      <div class='menuContent'>
        <ul>
          <li>Home</li>
          <li>About</li>
          <li>Contact</li>
          <li>Testimonial</li>
          <li>About us</li>
        </ul>
      </div>
    </div>
     
    <script
      src="https://code.jquery.com/jquery-3.3.1.js"
       ></script>
    <script>
        $('.toggle').on('click', function() {
    	$('.menu').toggleClass('active');
    });
        
    </script>
    </body>
    </html>

    【讨论】:

    • 谢谢!对我有很大帮助!
    • 将 .menu 位置更改为左侧,保留值 70px,然后将 .menu 跨度定位到左侧,并留出一点边距以使其居中
    【解决方案2】:

    我认为下面的代码会对您有所帮助。 transform: rotate(-145deg) 用于孩子 1,transform: rotate(145deg) translate(-50%, -50%); 用于孩子 3

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
         
        <style>
        
    body {
      
        font-family: 'Roboto Condensed', sans-serif;  
      font-size: 16px;
        overflow: hidden;
        text-transform: uppercase;
        font-weight: bold;
    }
    .menu {
      height: 70px;
      width: 70px;
      left: 70px;
      top: 20px;
      text-align: center;
      position: absolute;
      background: #f463c3;
      overflow: hidden;
      transition: all 0.2s ease;
      z-index: 999;
    }
    .menu.active {
      width:85%;
      transition:width 0.3s;
       -webkit-transition:width .3s;
       -moz-transition: width 0.3s;
        
    }
    .menu span {
    width: 70px;
    height: 70px;
    position: absolute;
    right: 0;
    cursor: pointer;
    background: #f463c3;
    z-index: 1;
    left: 0;
    }
    .menu.active .menuContent * {
      opacity: 1;
    }
    .menu.active span i:nth-child(1) {
      transform: rotate(-145deg) translate(-50%, -50%);
       top: 50%;
    }
    .menu.active span i:nth-child(2) {
      transform: translateX(-100px);
      opacity: 0;
    }
    .menu.active span i:nth-child(3) {
      transform: rotate(145deg) translate(-50%, -50%);
      top: 50%;
    }
    .menu span {
      width: 70px;
      height: 70px;
      position: absolute;
      right: 0;
      cursor: pointer;
      background: #f463c3;
      z-index: 1;
    }
    .menu span i {
      position: absolute;
      transform-origin: 50% 50%;
      width: 45%;
      height: 2px;
      left: 0;
      right: 0;
      margin: auto;
      background-color: #ccc;
      transition: transform 0.3s ease, opacity 0.1s ease 0.1s;
    }
    .menu span i:nth-child(1) {
      top: 40%;
    }
    .menu span i:nth-child(2) {
      top: 50%;
    }
    .menu span i:nth-child(3) {
      top: 60%;
    }
    .menu .menuContent {
      position: absolute;
      width: 100%;
      height: 100%;
      line-height: 40px;
      right: 0px;
      text-align: center;
    }
    .menu .menuContent * {
      opacity: 0;
    }
    .menu .menuContent ul li {
      display: inline-block;
      margin-left: 50px;
      margin-right: 50px;
      color: #2d3235;
      transition: opacity 0.3s ease 0.3s;
      cursor: pointer;
      position: relative;
    }
    .menu .menuContent ul li:hover:before {
      opacity: 0.8;
      top: 13px;
      left: 20px;
    }
    .menu .menuContent ul li:hover:after {
      opacity: 0.8;
      bottom: 13px;
      left: -20px;
    }
            
        </style>
    </head>
    <body>
        <div class='menu'>
      <span class='toggle'>
        <i></i>
        <i></i>
        <i></i>
      </span>
      <div class='menuContent'>
        <ul>
          <li>Home</li>
          <li>About</li>
          <li>Contact</li>
          <li>Testimonial</li>
          <li>About us</li>
        </ul>
      </div>
    </div>
     
    <script
      src="https://code.jquery.com/jquery-3.3.1.js"
       ></script>
    <script>
        $('.toggle').on('click', function() {
    	$('.menu').toggleClass('active');
    });
        
    </script>
    </body>
    </html>

    【讨论】:

    • 这不好。导航栏仍然向左打开。自己测试一下。我不知道如何使它向右打开。
    • 我更改了我的代码。和你问的一样吗?
    • 但是再次......导航栏仍然向左打开......我想打开到右侧,菜单图标会在左上角。试想一下:垂直镜像兄弟。谢谢!
    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多