I have a web application created using Angular framework. Below is the code snippets for the template file and TypeScript file:
HTML:
<button class="btn btn-primay" (click)="changeColumnsSize()"> change column sizes</button>
<div class="row">
<div id="leftColumn" class="col-sm-{{leftColumnSize}}" style="background-color:lavender;">
.col-sm-8
</div>
<div id ="rightColumn" *ngIf="this.state===true" class="col-sm-{{rightColumnSize}}" style="background-color:lavenderblush;">
.col-sm-4
</div>
</div>
TS:
import { Component } from '@angular/core';
@Component({
selector: 'app-box',
templateUrl: './box.component.html',
styleUrls: ['./box.component.css']
})
export class BoxComponent {
leftColumnSize: number = 8;
rightColumnSize: number = 4;
colDifference: number = 2;
state: boolean = false;
constructor() { }
changeColumnsSize(){
if (this.state===false)
this.state = true;
else
this.state = false;
if(this.state===true) {
this.leftColumnSize-=this.colDifference;
this.rightColumnSize+=this.colDifference;
}
else if (this.state===false) {
this.leftColumnSize+=this.colDifference;
this.rightColumnSize-=this.colDifference;
}
}
}
When the button is clicked, the size of leftColumnSize
decreases to 8 and rightColumn
is displayed with a size of 4. Clicking the button again resets leftColumnSize
and removes rightColumn
.
I am looking to add a smooth transition or animation effect to this process. Could you assist me in writing the necessary CSS code for this animation?