Reputation: 1882
I have some content which is displayed at at a preview scale, by using em for everything and then scaling the root font size when I want to reduce/enlarge, so can you see the full content by clicking on the preview, at which point I use jQuery to animate the font-size up to 100%:
So basically:
CSS:
.example section {
font-size: 30%;
}
JS:
zoomed.animate({
fontSize: '100%'
});
But see the fiddle to get a better idea.
The problem is, that although the container is scaling with the font size, the browser will wrap the text at slightly different points throughout the animation - I understand the logistics of why this happens (different proportions of characters when rendered at different sizes/hinting etc.), but it looks awful. It's much more noticeable in Chrome than it is in Firefox. Interestingly IE10 doesn't change where the lines wrap at all. This is on Windows - possibly the font rendering on OSX doesn't have this issue.
Can anyone think of some kind of fix or workaround?
One workaround that I considered initially was:
Create the preview at 100% font size, split the text on whitespace, add it to the container one word at a time, when the container increases in height store the position, then wrap each line in an element with whitespace no-wrap and give the container overflow: hidden.
However as I want to use arbitrary HTML (including images sized in ems) for the previews, this isn't really feasible.
Upvotes: 1
Views: 1167
Reputation: 472
Hm. On my Mac, Firefox has no issues whatsoever, but Chrome is worse than I think you've noticed–the text exceeds the bounds of the container after the resize.
I think we might need to back up one step and think the problem through one more time. So:
overflow: auto;
)That process of reasoning led me to check your jsfiddle, and sure enough, it is not the case that the various parts in your example retain their relative sizes during the resize.
On my machine (a laptop, so the pixel sizes are small, but that doesn't affect the logic here), the individual text containers (the innermost .padder
) have an aspect ratio of 143px / 53px = 2.70
, while the outer container (.examples
) has an aspect ratio of 526px / 253px = 2.08
.
This has the following consequences:
There is only one solution I can see to prevent the problem you're experiencing: force the outer container and text containers to have the same aspect ratio (i.e. since any solution that involves using actual HTML text and changes the aspect ratio during transformation will have the same issue).
This should also correct the problem that I'm seeing in Chrome where the text height exceeds the height of the container. This is happening because the number of lines changes, but the height of the scaled-up text container is predetermined by the outer container (which is completely unconnected to the height of the text in the text container).
Upvotes: 0
Reputation: 23558
the idea is that by enlarging regular text, you are giving away the decision of how to enlarge it to css/html. You want to devise a method where you have more control on the animating and zooming of your text.
An example of that would be converting your text into a bitmap then scaling it. That would be a poor choice for obvious reasons, such as the high cost of converting a font into a bitmap, as well as that a bitmap itself will look pixelated once it's scaled (ie there is quality loss). Additionally, even using css scale()
causes some blurring when you zoom in and out (see comments under original question).
my suggestion:
Canvas
and VML
to render the fonts. from flotcharts.org:
// Update the random dataset at 25FPS for a smoothly-animating chart
setInterval(function updateRandom() {
series[0].data = getRandomData();
plot.setData(series);
plot.draw();
}, 40);
This way you can totally control your animation wrapping and ensure that no pixelation/zooming is happening.
Upvotes: 1
Reputation: 11210
Using css letter-spacing ing the div.padder
like:
letter-spacing: 1px;
makes a bit of difference, thought I don't know if it's exactly the change you're hoping for.
Upvotes: 0
Reputation: 945
I suggest using a monospaced font - that would eliminate the small spacing changes that you're seeing when the font size is changing on animation. Here is one that you can try on Google Web Fonts to see if, at least, you don't get the same issues.
Upvotes: 0