【问题标题】:How do I alter the transition of my slide in full-width menu如何在全角菜单中更改幻灯片的过渡
【发布时间】:2015-12-12 22:53:11
【问题描述】:

我有一个基本的全屏滑入式菜单。它从左上角向外扩展以适应全屏。但是,我不希望它向外扩展。相反,我希望它从左侧滑入只是​​为了占据全屏。这可能吗?

<div class="top">
    <!-- place brand icon here -->
</div>

<div class="menu-collapsed">
  <div class="bar"></div>
       <nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Clients</a></li>
    <li><a href="#">Contact Us</a></li>
    <li><a href="#">Clients</a></li>
    <li><a href="#">Contact Us</a></li>
  </ul>
</nav>  
</div>


<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis sunt mollitia molestiae maxime, voluptatibus, voluptas placeat minima natus temporibus culpa repudiandae! Nam porro molestiae possimus, laboriosam, vero tenetur consequatur voluptatibus?</p>



html, body {
  padding: 0;
  margin: 0;
  height: 100%;
}

body {
  height: 100%;
  background-color: #369;
}

body.no-scroll {
    overflow-y:hidden;  
}

.top {
  width:100%;
  height:80px;
  background:#202020;
  position:fixed;
  top:0;
}

.menu-collapsed {
  transition: all .25s;
  position: fixed;
  top: 10px;
  right: 40px;
  height: 36px;
  width: 36px;
  z-index: 1;
  cursor: pointer;
}
.menu-collapsed ul {
  transition: all .05s;
  position: fixed;
  left: -9000px;
  top:0;
  bottom:0;
  display:none;
}

.bar {
  position: fixed;
  right: 36px;
  top: 40px;
  height: 4px;
  width: 40px;
  background-color: rgba(255, 255, 255, 0.75);
}
.bar:before {
  transition: all .25s;
  content: "";
  position: absolute;
  left: 0;
  top: -12px;
  height: 4px;
  width: 40px;
  background-color: rgba(255, 255, 255, 0.75);
}
.bar:after {
  transition: all .25s;
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  height: 4px;
  width: 40px;
  background-color: rgba(255, 255, 255, 0.75);
}

.menu-expanded {
  transition: all 8.25s;
  text-align: center;
  line-height: 200px;
  height: 100%;
  width: 100%;
  border-radius: 0px;
  top: 0;
  left: 0;
  bottom:0;
  right:0;
  background-color: rgba(0, 0, 0, 0.85);
  overflow-y:scroll;
}
.menu-expanded ul {
  transition: all .05s;
  position: relative;
  left: 0;
  top:0;
  bottom:0;
  z-index: 8888;
  display:block;
}
.menu-expanded a {
  transition: all .15s;
  text-decoration: none;
  color: white;
  font-size: 2em;
  font-family: 'Quicksand', sans-serif;
  padding: 5px;
}
.menu-expanded a:hover {
  transition: all .15s;
  letter-spacing: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.menu-expanded .bar {
  background-color: transparent;
  transition: all .25s;
  right:50px;
}
.menu-expanded .bar:before {
  transition: all .25s;
  content: "";
  transform: rotate(45deg);
  top: -0px;
}
.menu-expanded .bar:after {
  transition: all .25s;
  content: "";
  transform: rotate(-45deg);
  top: 0px;
}

h1 {
  font-size: 3em;
  color: white;
  font-family: 'Quicksand', sans-serif;
  text-align: center;
  line-height: 250px;
}

p {
  width: 80%;
  margin: 0 auto;
  color: white;
  line-height: 1.8em;
  font-family: 'Quicksand', sans-serif;

}




$(document).ready(function() {
   $('.menu-collapsed').click(function() {
      $(this).toggleClass('menu-expanded');
      $('body').toggleClass('no-scroll');
    });
});

我已将它放在 codepen 上(由于某种原因,它在这里根本不起作用)http://codepen.io/anon/pen/Ywypby 但我认为这是因为 Codepen 不会运行脚本。

【问题讨论】:

    标签: css css-transitions


    【解决方案1】:

    您的动画在 codepen 中不起作用的原因是您没有在 JS 部分中加载 JQuery。只需单击小设置图标并将其加载到项目中。

    要让您的动画从左侧滑入,您只需将过渡定位在 .menu-collapsed 和 .menu-expanded....

    而不是

    transition: all XXs;
    

    transition: width XXs;
    

    XX 正是你过渡的时候。

    http://codepen.io/anon/pen/Ywypby

    【讨论】:

    • 非常感谢@jared。我认为需要 JQuery 的链接,但不确定如何在 Codepen 中添加它。谢谢你,我现在知道了。加上将所有更改为宽度效果完美。我确实尝试了“左”,但杰克 sh*t 确实如此 :)
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多