【发布时间】:2020-08-19 22:42:53
【问题描述】:
我正在使用 angular 10,我想创建一个界面,当您单击一个元素(数组 [???])时,其他元素会折叠(在这个更简单的版本中更改颜色和宽度)。
然后,如果您单击另一个,则会恢复正常,而所有其他都崩溃,如果您再次单击第二个,则一切都会恢复正常。
图片在底部。
我只能做与第一部分相反的事情:如果你点击一个元素,这一个会改变。
HTML:
<div *ngFor="let name of disney" class="basic" (click)="function(name)" [class.selected]="clickedClass === name">
{{name}}
</div>
Ts:
disney: string[] = ['pippo', 'pluto', 'topolino'];
clickedClass: any;
function(name) {
this.clickedClass = name;
}
CSS:
.basic {
height: 50px;
background-color: beige;
}
.selected {
height: 100px;
background-color: burlywood;
}
3张图片让你明白我的意思:
If you click on the opened paragraph you'll go to the 1st image
【问题讨论】:
标签: css angular typescript