动画固定位置侧边栏

时间:2018-10-18 02:36:34

标签: css css3 css-transitions css-animations

我正在尝试将固定的侧边栏幻灯片放进去,或者一般来说只是设置动画,但是我似乎不知道该怎么做。我尝试通过仅添加一些过渡和常规动画来尝试,但它们似乎不起作用。如果可能,我需要将其固定。任何帮助表示赞赏。

$('.open-menu').click(function() {
  $(".sidebar").toggleClass('open')
  $("body").toggleClass('no-scroll')
});
.wrap {
  margin-bottom: 54px;
}

.sidebar {
  background: black;
  width: 280px;
  height: calc(100% - 50px);
  position: fixed;
  -webkit-transform: translate3d(-100%, 0px, 0px);
  transform: translate3d(-100%, 0px, 0px);
  display: none;
  -webkit-transition: all .3s ease-in-out;
  -moz-transition: all .3s ease-in-out;
  -o-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
  -webkit-animation: scale-up-center 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) 0ms both;
  animation: scale-up-center 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) 0ms both;
  overflow-y: auto;
  z-index: 10;
}

.open {
  display: block !important;
  -webkit-transform: translate3d(0px, 0px, 0px);
  transform: translate3d(0px, 0px, 0px);
  -webkit-animation: scale-up-center 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) 0ms both;
  animation: scale-up-center 0.4s cubic-bezier(0.390, 0.575, 0.565, 1.000) 0ms both;
}

.no-scroll {
  position: fixed;
}

.content {
  flex-basis: 0;
  -ms-flex-positive: 1;
  flex-grow: 1;
  /* max-width: 100%; */
  position: relative;
  /* width: 100%; */
  min-height: 1px;
}

.drawer-btn-container {
  display: block;
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.drawer-btn {
  width: 100%;
  display: block;
  text-align: center;
  padding: 1rem;
  background: green;
  color: white;
}


/*Small devices (landscape phones, 576px and up)*/

@media (min-width: 576px) {}


/*Medium devices (tablets, 768px and up)*/

@media (min-width: 768px) {}


/*Large devices (desktops, 992px and up)*/

@media (min-width: 992px) {}


/*Extra large devices (large desktops, 1200px and up)*/

@media (min-width: 1200px) {
  .sidebar {
    display: block;
    -webkit-transform: translate3d(0px, 0px, 0px);
    transform: translate3d(0px, 0px, 0px);
    position: relative;
    overflow: hidden;
    height: 100%;
    -ms-flex-preferred-size: 0;
    /* flex-basis: 0; */
    -ms-flex-positive: 1;
    /* flex-grow: 1; */
    /* max-width: 100%; */
    position: relative;
    /* width: 100%; */
    min-height: 1px;
    width: 280px;
  }
  .wrap {
    margin-bottom: 0;
  }
  .drawer-btn-container {
    display: none;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="container-fluid p-0 wrap">
  <div class="row no-gutters">
    <div class="col-auto scale-up-center">
      <div class="sidebar">


        Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>Sidebar<br>bottom<br></div>
    </div>
    <div class="col">
      <div class="content">Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>Content<br>bottom<br></div>
    </div>
  </div>
</div>

<div class="drawer-btn-container">
  <div class="row">
    <div class="col">
      <a href="#" class="drawer-btn open-menu">Main Menu</a>
    </div>
  </div>
</div>

http://jsfiddle.net/4xt9e2ro/

1 个答案:

答案 0 :(得分:1)

.sidebar表单中删除display: none;,将.open更改为.sideba.open并删除display:block !important;

但是说实话,您的CSS有点混乱。您使用动画,但未声明密钥。请阅读以下内容:https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations

欢呼