slideOut侧栏再次出现

时间:2018-08-29 15:45:57

标签: html css angular css3 css-animations

我有一个滑入/滑出的侧边栏。当我在按钮上滑出时,它会向右滑动以隐藏,但在应隐藏时会再次出现。

单击按钮时出现侧边栏,并且在按x图标时将其隐藏

CSS

.pay-storage-container {
  $inner-padding: 16px;
  height: 100vh;
  position: fixed;
  right: 0;
  top: 0;
  width: 325px;
  border: 1px solid #c0c2c7;
  z-index: 1;
  //Other subclasses
}

.showSideBar {
  animation: slideIn 1s;
}

.closeSideBar {
  animation: slideOut 1s;
}

@keyframes slideIn {
  0% {
    opacity: 0;
    transform: translateX(350px);
  }

  100% {
    opacity: 1;
    transform: translate(0);
  }
}

@keyframes slideOut {
  100% {
    opacity: 1;
    transform: translateX(350px);
  }
}

HTML

<div class="pay-storage-container {{toggleSideBar ? 'showSideBar' : 'closeSideBar'}}">
  <div class="header-container">
    <div class="header">Pay Storage</div>
    <span class='close-icon csx-common_delete' (click)="closeSideBar()"></span>
  </div>
  <div class="pay-storage-inner">
    <div *ngIf="paymentMessage$ | async as message">
      {{ message | json }}
    </div>
    <app-equipment-summary [equipmentSummary]='equipmentSummary'></app-equipment-summary>
    <app-credit-card #creditCardForm></app-credit-card>
    <div>
    </div>
  </div>
  <div class="footer-container">
    <button pButton type="button" label="Submit Payment" class="x-primary-green-400" [disabled]='!creditCardForm.creditCardForm.valid'
      (click)="onSubmitPayment()"></button>
  </div>
</div>

我在此项目中使用了angular,并且在.TS文件中有一个变量,可用于切换类以更改滑动位置。

TS

toggleSideBar = true;
.
.
.
closeSideBar() {
    this.toggleSideBar = false;
}

我非常好,这是css的问题,而不是棱角分明的问题,但是我还是补充说,以防万一你想看看

1 个答案:

答案 0 :(得分:1)

您可以将animation-fill-mode: forwards;添加到closeSideBar类中。这样可以确保动画达到100%后不会重置

.pay-storage-container {
  $inner-padding: 16px;
  height: 100vh;
  position: fixed;
  right: 0;
  top: 0;
  width: 325px;
  border: 1px solid #c0c2c7;
  z-index: 1;
  //Other subclasses
}

.showSideBar {
  animation: slideIn 1s;
}

.closeSideBar {
  animation: slideOut 1s;
  animation-fill-mode: forwards;
}

@keyframes slideIn {
  0% {
    opacity: 0;
    transform: translateX(350px);
  }

  100% {
    opacity: 1;
    transform: translate(0);
  }
}

@keyframes slideOut {
  100% {
    opacity: 1;
    transform: translateX(350px);
  }
}
<div class="pay-storage-container closeSideBar">
  <div class="header-container">
    <div class="header">Pay Storage</div>
    <span class='close-icon csx-common_delete' (click)="closeSideBar()"></span>
  </div>
  <div class="pay-storage-inner">
    <div *ngIf="paymentMessage$ | async as message">
      {{ message | json }}
    </div>
    <app-equipment-summary [equipmentSummary]='equipmentSummary'></app-equipment-summary>
    <app-credit-card #creditCardForm></app-credit-card>
    <div>
    </div>
  </div>
  <div class="footer-container">
    <button pButton type="button" label="Submit Payment" class="x-primary-green-400" [disabled]='!creditCardForm.creditCardForm.valid'
      (click)="onSubmitPayment()"></button>
  </div>