Reputation:
I have a sidebar that I'm sliding in/out. When I slideOut on a button press it slides to the right to hide, but reappears again when it should be hidden.
Sidebar appear on button click and it hides when you press the x icon
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>
I'm using angular in this project and I have a variable in a .TS file that toggles the classes to change the sliding in/out.
TS
toggleSideBar = true;
.
.
.
closeSideBar() {
this.toggleSideBar = false;
}
I'm very super it's a problem with the css not with the angular side, but I still added in case y'all wanted to take a look
Upvotes: 1
Views: 43
Reputation: 18281
You can add animation-fill-mode: forwards;
to the closeSideBar
class. This will ensure that the animation is not reset after it reaches 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>
Upvotes: 1