STRML / textFit

A jQuery-free component that quickly fits single and multi-line text to the width (and optionally height) of its container.
https://textfit.strml.net
637 stars 123 forks source link

Fixed textFit working with chrome and various sizes and using % #32

Open hovi opened 6 years ago

hovi commented 6 years ago

I tried to use this library, but I kept having these strange things happening - sometimes at specific width/height of my browser using Chrome, I always had textFit finishing with minimum font size although there was a lot of space. After debugging I found out, that scrollWidth and originalWidth (or with height) was 1 and it never matched the condition. I am pretty sure this was caused by rounding error either in browser itself or somewhere in your code (I suspect it's chrome issue), because I am using different units (%, em).

Once I changed condition to accept 1 px difference, code works fine in Chrome too, but it also changes behaviour as it may detect something sooner/later, etc.

This is probably not ideal fix, but it works for me well. Not expect this to be merged, but to discuss this.