-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Character size based fitting (width & height), compressor removed #6
base: master
Are you sure you want to change the base?
Conversation
Changed resizing to be done based on character dimensions vs. font-size, as opposed to a fixed number based on container width (i.e. compressor - obsolete now). Takes container height into account as well, so it will never be bigger than it.
Wow. Looks fun! I'll have to download it and put it through its paces to see if it's what I think should become the standard. That might take a while given my current workload at the moment. Do you have a JSBin or something like that to show the use case for needing it to fit a height as well as a width? |
I could whip up a short jsbin, but give me a couple of days please (guess we have similar workloads). Otherwise just use the example.html. On my screen (1280x800), I can see it stop fitting the width, at a certain point (horizontal space just gets larger), meaning vertical fitting is happening (but since the height doesn't change, neither does the font-size). |
ok, so here's a quick test, not very pretty, but it does the job: The second box is for height testing. I haven't changed the js code, so depending on how you're scaling, height/width fitting might kick in.
|
Hi Armin, I've implemented your version of this code but sometimes the resized text randomly appears about twice as large as it should. I'm afraid I can't give you any other information on this problem. It seems to happen one out of every 3 or 4 times the page is loaded. Do you have any idea why this might be happening? |
That's weird. Do you have an example (jsfiddle) handy? Are you use @font-face to load custom fonts? Try executing fitText on Also, log the values fittext is using (in jquery.fittext.js), you might figure out what's happening. I'd also log to see if it does width or height fitting. |
Using $(window).load(function () seems to have fixed that problem! Thank you! Another question though - does this fork support min and max font size? |
For extra performance, if you are using google webfonts (if I recall correctly, you are), you could bind fitText to the event that is fired when they're done loading: WebFont Loader > Events |
Anyway possible to merge this? https://coderwall.com/p/_8jxgw/autoresize-text-to-fit-into-a-div-width-height |
Hey,
This is my first public fork, so it might be a bit overkill. Basically I needed height fitting as well, so I changed the whole shabang to calculate optimal sizes based on character dimensions (at given font-size) vs. container width.
The one big difference in implementation, is that texts need to be set to
width: auto
andwhitespace: nowrap;
is encouraged (should work without that, but I'm thinking of@font-face
fonts, which might load late and bork it up).I've tested it on a page with 200 fit-able texts, 20 fonts, worked fine.
Hope you like it,
Armin