请看下图。我在画布上有 p 标签列表。在画布下方,我有多种颜色和字体大小。
下面是我的场景
- 在画布上添加文本。我可以根据需要添加任意数量。
- 选择任何文本并更改所选 p 标签的颜色和字体大小。
目前我做了以下代码:
1. HTML
<ion-row #canvasRow id="canvasRow">
<ion-col *ngFor="let textarea of textAreasList; let textarea_index= index">
<p absolute-drag style="border: 1px dotted black;
height: 40px;
width: 60%;
z-index: 10000;" (click)="changeTextStyle($event)" (txtCChange)="changeTxtColor($event)"
(txtSChange)="changeTxtSize($event)">{{textarea}}</p>
<button (click)="removeTextArea(textarea_index)">Remove</button>
</ion-col>
</ion-row>
2.色码选择
<ion-row id="top-toolbar">
<ion-col>
<ion-scroll scrollX="true">
<ion-buttons id="ionBtnGroup">
<button *ngFor="let colour of availableColours" icon-only ion-button (click)="changeColour(colour)">
<ion-icon [style.color]="colour" name="brush"></ion-icon>
</button>
</ion-buttons>
</ion-scroll>
</ion-col>
</ion-row>
3.字体更改代码
<ion-buttons right *ngIf="!isDraw && !isRotate" >
<button color="dark" ion-button icon-only (click)="changeFontSize(10)"><div class="galeria"><span>10px</span></div></button>
<button color="dark" ion-button icon-only (click)="changeFontSize(15)"><div class="galeria"><span>15px</span></div></button>
<button color="dark" ion-button icon-only (click)="changeFontSize(20)"><div class="galeria"><span>20px</span></div></button>
<button color="dark" ion-button icon-only (click)="changeFontSize(30)"><div class="galeria"><span>30px</span></div></button>
<button color="dark" ion-button icon-only (click)="changeFontSize(50)"><div class="galeria"><span>50px</span></div></button>
</ion-buttons>
4.字体更改功能
changeFontSize(size){
this.selectedFontSize = size+'px';
this.txtSChange.emit({size: size+'px'});
}
5.换色功能
changeColour(colour){
if(this.isDraw){
this.currentColour = colour;
}else{
this.selectedColor = colour;
this.txtCChange.emit({color: colour});
}
}
6. 颜色和字体大小适用代码
@Output() txtCChange = new EventEmitter();
@Output() txtSChange = new EventEmitter();
changeTextStyle(event: Event){
let element = event.target as HTMLInputElement;
element.style.color = this.selectedColor;
element.style.fontSize = this.selectedFontSize;
}
changeTxtColor(event){
this.selectedColor = event.color;
this.changeTextStyle(event);
}
changeTxtSize(event){
this.selectedFontSize = event.size;
this.changeTextStyle(event);
}
如果有任何困惑,请告诉我。上面的代码不起作用。我想知道更有效的方法。