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

Doesn't work on "hidden" elements #45

Open MarcusU opened 3 years ago

MarcusU commented 3 years ago

I have a couple divs that I show/hide using element.hidden = true etc. My code sets all the text, then unhides. If I run the textFit(myElement) before setting hidden to false, then it defaults to the smallest text size.
Is there a way to make this work on hidden elements?

MarcusU commented 3 years ago

Perhaps a way to pass in the height and width of the element instead of deriving it? I know the height and width beforehand

MarcusU commented 3 years ago

I've managed to get a working version of this. Maybe not the best way to make it work, but it works for my purposes. I'll try to clean it up and create a PR in the next few days.

sarahg commented 3 years ago

@MarcusU I just ran into this as well, doing something similar. Can you share how you got yours to work, even if it's not a PR yet? I have a (very bad) hack in place for now, but I would love to make it less of a landmine for my future self. :)