html - slideOut 侧边栏再次出现

标签 html angular css 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 的问题,而不是 Angular 边的问题,但我还是补充说,以防你们都想看一看

最佳答案

您可以将 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>

关于html - slideOut 侧边栏再次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52081464/

相关文章:

html - Canvas 响应式设计

具有最小宽度和最大宽度的 HTML 全屏布局

使用 typescript 和 npm 将外部组件导入到 angular2 快速启动项目中

Angular:Http 到 HttpClient 的转换问题

javascript - 如何成为@media 的第一名?

css - 使用 CSS 在 DIV 上放置关闭按钮

html - 具有绝对位置的 div 交叉悬停菜单

java - 为什么这段代码不显示 HTML 文件?

html - 在不更改 HTML 的情况下为移动和桌面 View 重新安排 flex 元素

Angular - 连接到代理服务器并获得响应,但随后显示尝试代理到 : localhost to actual server 时发生错误