Now max font size works also if container is resized

This commit is contained in:
Lorenzo Iovino 2017-06-19 11:42:53 +02:00
parent e195405898
commit 85d3b3af89
2 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "ng2-fittext", "name": "ng2-fittext",
"version": "1.0.18", "version": "1.0.19",
"description": "An Angular2 directive for autoscale the font size of an element to fit an upper level container.", "description": "An Angular2 directive for autoscale the font size of an element to fit an upper level container.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View file

@ -42,6 +42,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
} else { } else {
this.setFontSize(this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth); this.setFontSize(this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth);
} }
this.ngAfterViewInit(); this.ngAfterViewInit();
} }
} }
@ -72,6 +73,12 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
: this.checkOverflow(this.el.nativeElement.parentElement, this.el.nativeElement); : this.checkOverflow(this.el.nativeElement.parentElement, this.el.nativeElement);
if (overflow) { if (overflow) {
this.setFontSize(this.calculateFontSize(this.fontSize, this.speed)); this.setFontSize(this.calculateFontSize(this.fontSize, this.speed));
if (this.useMaxFontSize) {
if(this.fontSize > this.maxFontSize){
this.maxFontSize = parseInt(window.getComputedStyle(this.el.nativeElement).fontSize, null);
this.setFontSize(this.maxFontSize);
}
}
this.ngAfterViewInit(); this.ngAfterViewInit();
} }
} }