I have an Angular application. Its HTML file contains a div with class row which itself contains two divs with class col. By clicking on the button, the size of the columns change:
<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>
To have a smooth resize, I have added transition property to the col classes in the CSS file:
.col-sm-8 { transition: width .5s ease; }
.col-sm-4 { transition: width .5s ease ; }
The TS file (that contains the changeColumnsSize function) looks like this:
export class BoxComponent {
leftColumnSize: number = 12;
rightColumnSize: number = 0;
colDifference: number = 4;
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;
}
}
}
However, there is a problem. Every time the transition occurs, the rightColumn appears below the leftColumn, then moves up to the correct place.
Can you help me solving this? I prefer to solve this without using Angular animations.