gpt4 book ai didi

css - 平稳过渡

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:47 25 4
gpt4 key购买 nike

我有一个用 Angular 编写的应用程序。下面是模板和 TS 文件的代码:

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;
}
}
}

通过单击按钮,leftColumnSize 的大小减小到 8,rightColumn 以 4 大小呈现。再次单击它,leftColumnSize 重置并且 rightColumn 被删除。但我希望这一切以一种平滑的方式发生,一种过渡或动画。你能帮我写相关的CSS代码吗?

最佳答案

您可以使用 CSS 过渡属性:

例如:

.col-sm-8 {
width: 60%;
transition: width .5s ease;
}

.col-sm-4 {
width: 40%;
transition: width .5s ease;
}

.col-sm-2 {
width: 20%;
transition: width .5s ease;
}

您还可以通过为动画元素创建通用的 .transition 类来优化它。

.transition {transition: width .5s ease;}

关于css - 平稳过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52265056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com