WebKit text-rendering & transitions

A test for text rendering method changes during transition to infer when redraws occur.

by Barney Carroll

HTML

<p>Webkit has often had weird issues with text-rendering flickers when using cutting-edge[1] CSS tricks. This demos a way of keeping it in check that works with transitions as of 11/09/2012. Click the first button a couple times to see the effect. Click the second button to fix it.</p>
<a href="#" data-toggle-class="transition">
  Toggle transition
</a>
<a href="#" data-toggle-class="backfaceVisibilityHidden">
  Toggle backface-visibility
</a>
<small>
    Update:<br/>
    <ul>
        <li>On my Safari iOS 5, this resolves fucked-up glyphs and flickering whole-screen black-out.</li>
        <li>On Chrome 21, it fixes a sudden switch to an ultra-heavy anti-aliasing method.</li>
        <li>On Safari 5 for OSX, <em>it does the opposite</em> &#8212; ie fine without the hack, activates the bug on hack application.</li>
        <li>Other browsers are not affected.</li>
    </ul>
    [1] Cutting edge reffers pretty much to the whole of CSS3's new features. You might argue that these are no longer really cutting edge: the fact that WebKit drastically alter the way they deal with their rendering every couple of months leads me to disagree.
</small>

CSS

@import url(http://fonts.googleapis.com/css?family=Londrina+Outline);

body {
    font: 2em/1.5 'Londrina Outline';
    padding: 1em;
    
       -moz-transition: all 1s ease-in-out; 
    -webkit-transition: all 1s ease-in-out; 
         -o-transition: all 1s ease-in-out; 
            transition: all 1s ease-in-out; 
}

a {
    display: block;
}

.transition {
    opacity: .4;
    padding-left: 10em;
}

.backfaceVisibilityHidden {
       -moz-backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
}

small {
    display: block;
    font: .5em/1.5 sans-serif;
    margin: 1em 0;
}

JavaScript

$(document).on('click','[data-toggle-class]',function(){
    $('body').toggleClass($(this).attr('data-toggle-class'));
});