Resolved long word break fit
This commit is contained in:
parent
7b51b80e91
commit
9d15ae732f
2 changed files with 6 additions and 4 deletions
|
|
@ -70,7 +70,6 @@ For sure is not a good implementation, maybe is not the best way to do it, but,
|
||||||
### Todos
|
### Todos
|
||||||
|
|
||||||
- Write tests
|
- Write tests
|
||||||
- Resolve the problem with long word checking the overflowY
|
|
||||||
- Find a better algorithm to find the font-size who fits better the container
|
- Find a better algorithm to find the font-size who fits better the container
|
||||||
|
|
||||||
License
|
License
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ export class FittextDirective implements AfterViewInit {
|
||||||
constructor(public el: ElementRef, public renderer: Renderer) {
|
constructor(public el: ElementRef, public renderer: Renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkOverflowX(parent:any, children:any) {
|
checkOverflow(parent:any, children:any) {
|
||||||
return children.clientHeight > parent.clientHeight;
|
return (children.clientHeight > parent.clientHeight || children.scrollWidth > parent.clientWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:resize', ['$event'])
|
@HostListener('window:resize', ['$event'])
|
||||||
|
|
@ -32,8 +32,11 @@ export class FittextDirective implements AfterViewInit {
|
||||||
this.fontSize = this.container.clientWidth;
|
this.fontSize = this.container.clientWidth;
|
||||||
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
|
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
|
||||||
}
|
}
|
||||||
let overflow = this.checkOverflowX(this.container, this.el.nativeElement);
|
let overflow = this.checkOverflow(this.container, this.el.nativeElement);
|
||||||
if(overflow) {
|
if(overflow) {
|
||||||
|
if(this.fontSize < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.fontSize = Math.floor(this.fontSize/this.speed);
|
this.fontSize = Math.floor(this.fontSize/this.speed);
|
||||||
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
|
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
|
||||||
this.ngAfterViewInit();
|
this.ngAfterViewInit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue